Clojure

clojure.java.io/copy interprets read count of 0 as eos

Details

  • Type: Defect Defect
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Declined
  • Affects Version/s: None
  • Fix Version/s: None
  • Component/s: None
  • Labels:
    None

Description

According to the interface http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#read()
InputStream.read() family of methods return -1 when the end of stream is reached.

do-copy methods currently use a test: (pos? size) to determine whether eos is reached. This mostly works, but the specification is pretty clear in that InputStream implementations are allowed to return reads of zero bytes before returning more bytes.

##EDIT changed title of ticket from "clojure.java.io/copy should test for -1 instead of 0 for end of stream"

Activity

Hide
Herwig Hochleitner added a comment -

Attached patch changes do-copy methods to test for -1

Show
Herwig Hochleitner added a comment - Attached patch changes do-copy methods to test for -1
Herwig Hochleitner made changes -
Field Original Value New Value
Attachment 0001-CLJ-1089-clojure.java.io-do-copy-methods-determine-e.patch [ 11599 ]
Herwig Hochleitner made changes -
Description According to the interface http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#read()
InputStream.read() family of methods return -1 when the end of stream is reached.

do-copy methods currently use a test: (pos? size) to determine whether eos is reached. This mostly works, but the specification is pretty clear in that InputStream implementations are allowed to return reads of zero bytes before returning more bytes.
According to the interface http://docs.oracle.com/javase/6/docs/api/java/io/InputStream.html#read()
InputStream.read() family of methods return -1 when the end of stream is reached.

do-copy methods currently use a test: (pos? size) to determine whether eos is reached. This mostly works, but the specification is pretty clear in that InputStream implementations are allowed to return reads of zero bytes before returning more bytes.

##EDIT changed title of ticket from "clojure.java.io/copy should test for -1 instead of 0 for end of stream"
Summary clojure.java.io/copy should test for -1 instead of 0 for end of stream clojure.java.io/copy interprets read count of 0 as eos
Hide
Andy Fingerhut added a comment -

Herwig, can you elaborate on "the specification is pretty clear in that InputStream implementations are allowed to return reads of zero bytes before returning more bytes"?

I ask because in the very InputStream documentation page you link to, it seems to explicitly say the opposite of what you claim: "If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b."

Show
Andy Fingerhut added a comment - Herwig, can you elaborate on "the specification is pretty clear in that InputStream implementations are allowed to return reads of zero bytes before returning more bytes"? I ask because in the very InputStream documentation page you link to, it seems to explicitly say the opposite of what you claim: "If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b."
Hide
Herwig Hochleitner added a comment -

I reread the spec for InputStream.read and it clearly says

"If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b."

The reason I originally thought of this as an issue was a misbehaving ServletInputStream from Jetty.

I closed the issue as declined. Sorry for the noise!

Show
Herwig Hochleitner added a comment - I reread the spec for InputStream.read and it clearly says "If no byte is available because the stream is at the end of the file, the value -1 is returned; otherwise, at least one byte is read and stored into b." The reason I originally thought of this as an issue was a misbehaving ServletInputStream from Jetty. I closed the issue as declined. Sorry for the noise!
Herwig Hochleitner made changes -
Resolution Declined [ 2 ]
Status Open [ 1 ] Closed [ 6 ]

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: