Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
align eoffh on jvm to moar/parrot
So we recognize EOF right at EOF from a user perspective.
  • Loading branch information
FROGGS committed Sep 17, 2014
1 parent 2b8753c commit 4ee0023
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/vm/jvm/runtime/org/perl6/nqp/io/FileHandle.java
Expand Up @@ -13,6 +13,7 @@
public class FileHandle extends SyncHandle implements IIOSeekable {

FileChannel fc;
protected boolean eof = false;

public FileHandle(ThreadContext tc, String filename, String mode) {
try {
Expand Down Expand Up @@ -78,4 +79,24 @@ public void flush(ThreadContext tc) {
throw ExceptionHandling.dieInternal(tc, e);
}
}

public boolean eof(ThreadContext tc) {
if (eof)
return true;
else if (readBuffer != null && readBuffer.remaining() > 0)
return false;
else {
try {
long position = fc.position();
getc(tc);
fc.position(position);
readBuffer = null;
return false;
}
catch (Exception e) {

This comment has been minimized.

Copy link
@coke

coke Sep 24, 2014

Contributor

this should probably catch the specific exception.

This comment has been minimized.

Copy link
@FROGGS

FROGGS Sep 24, 2014

Author Contributor

I am not a Java professional: So what do you mean exactly?

This comment has been minimized.

Copy link
@teodozjan

teodozjan Sep 24, 2014

Contributor

Coke meant catchin Exception is bad practice. It Should be IOException IMHO

Catching all exceptions may suppress problems programmer didn't except and for example NullPointerException or IllegalArgumentException etc will trigger same code as there was problem with reading file

eof = true;
return true;
}
}
}
}

0 comments on commit 4ee0023

Please sign in to comment.