Skip to content

Instantly share code, notes, and snippets.

@nobeans
Created September 6, 2018 02:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nobeans/03ca936751bdb0e7d8ba1611e6fe1032 to your computer and use it in GitHub Desktop.
Save nobeans/03ca936751bdb0e7d8ba1611e6fe1032 to your computer and use it in GitHub Desktop.
def f = new File("/tmp/test.dat")
f.text = "1234567890" * 2
def tryRead(ins) {
def buff = new byte[9]
println ins.read(buff)
println new String(buff)
}
f.withInputStream { ins ->
tryRead(ins)
tryRead(ins)
tryRead(ins)
tryRead(ins)
tryRead(ins)
}
// 9
// 123456789
// 9
// 012345678
// 2
// 90 <---EOFの直前までで一度正しく読み込める
// -1
// <---EOF検出時にはデータは空
// -1
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment