Smallville7123
03/29/2019, 9:45 PMbbaldino
03/29/2019, 10:55 PMlexer#clone
you can't create an instance of lexer
? what error do you get?Smallville7123
03/29/2019, 11:29 PMCaused by: java.lang.NoSuchMethodError: Build_gradle$lexer.<init>(Ljava/nio/ByteBuffer;Ljava/lang/String;)V
at Build_gradle$lexer.clone(build.gradle.kts:258)
bbaldino
03/29/2019, 11:32 PMSmallville7123
03/29/2019, 11:55 PMimport java.io.File;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
fun fileToByteBuffer(f : File) : ByteBuffer {
val file = RandomAccessFile(f, "r")
val fileChannel = file.getChannel()
var i = 0
var buffer = ByteBuffer.allocate(fileChannel.size().toInt())
fileChannel.read(buffer)
buffer.flip()
return buffer
}
val filetmp = "/sda3_partition_resize_to_size"
class lexer(stm : ByteBuffer, delimiter : String) {
val f = stm
val delimiters = delimiter
fun clone() {
val ll = lexer(fileToByteBuffer(File(filetmp)), "none")
}
}
tasks.register("test") {
val lex = lexer(fileToByteBuffer(File(filetmp)), "none")
println("cloning")
lex.clone()
println("clone sucesfull")
}
app/build.gradle :
apply from: '../a/build.gradle.kts'
preBuild.dependsOn test
bbaldino
03/30/2019, 12:22 AMSmallville7123
03/30/2019, 12:41 AMbbaldino
03/30/2019, 1:03 AMSmallville7123
03/30/2019, 1:15 AMfun lexerClone(stm : ByteBuffer, tokens : String) : lexer {
return lexer(stm, tokens)
}
class lexer ...
val lex = lexer(fileToByteBuffer(File(src)), tokens)
println("cloning")
val la = lexer(lex.f.duplicate(), lex.delimiters)
println("clone made")
var line = lex.lex()
var laline = la.lex()
println("line is '$line'")
println("laline is '$laline'")
cloning
clone made
line is '
'
laline is '
'