Fix iolib test case. All junit tests now pass (against Lua 5.1.3 on GNU/Linux).
This commit is contained in:
@@ -52,8 +52,8 @@ public class IoLib extends LFunction {
|
||||
public int peek() throws IOException, EOFException;
|
||||
// return char if read, -1 if eof, throw IOException on other exception
|
||||
public int read() throws IOException, EOFException;
|
||||
// return length if fully read, false if eof, throw IOException on other exception
|
||||
public int readFully(byte[] bytes, int offset, int length) throws IOException;
|
||||
// return number of bytes read if positive, false if eof, throw IOException on other exception
|
||||
public int read(byte[] bytes, int offset, int length) throws IOException;
|
||||
}
|
||||
|
||||
|
||||
@@ -454,9 +454,10 @@ public class IoLib extends LFunction {
|
||||
|
||||
public static LValue freadbytes(File f, int count) throws IOException {
|
||||
byte[] b = new byte[count];
|
||||
if ( f.readFully(b,0,b.length) < 0 )
|
||||
int r;
|
||||
if ( ( r = f.read(b,0,b.length) ) < 0 )
|
||||
return LNil.NIL;
|
||||
return new LString(b);
|
||||
return new LString(b, 0, r);
|
||||
}
|
||||
public static LValue freaduntil(File f,int delim) throws IOException {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
|
||||
@@ -187,8 +187,8 @@ public class Cldc10IoLib extends IoLib {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// return length if fully read, -1 if eof, throws IOException
|
||||
public int readFully(byte[] bytes, int offset, int length) throws IOException {
|
||||
// return number of bytes read if positive, -1 if eof, throws IOException
|
||||
public int read(byte[] bytes, int offset, int length) throws IOException {
|
||||
int n,i=0;
|
||||
if (is!=null) {
|
||||
if ( length > 0 && lookahead >= 0 ) {
|
||||
@@ -196,10 +196,10 @@ public class Cldc10IoLib extends IoLib {
|
||||
lookahead = -1;
|
||||
i += 1;
|
||||
}
|
||||
for ( ; i<length; ) {
|
||||
for ( ; i<length; ) {
|
||||
n = is.read(bytes, offset+i, length-i);
|
||||
if ( n < 0 )
|
||||
return -1;
|
||||
return ( i > 0 ? i : -1 );
|
||||
i += n;
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -142,14 +142,12 @@ public class J2seIoLib extends IoLib {
|
||||
if ( file != null ) {
|
||||
if ( "set".equals(option) ) {
|
||||
file.seek(pos);
|
||||
return (int) file.getFilePointer();
|
||||
} else if ( "end".equals(option) ) {
|
||||
file.seek(file.length()+1+pos);
|
||||
return (int) file.length()+1;
|
||||
file.seek(file.length()+pos);
|
||||
} else {
|
||||
file.seek(file.getFilePointer()+pos);
|
||||
return (int) file.getFilePointer();
|
||||
}
|
||||
return (int) file.getFilePointer();
|
||||
}
|
||||
notimplemented();
|
||||
return 0;
|
||||
@@ -190,17 +188,12 @@ public class J2seIoLib extends IoLib {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// return length if fully read, -1 if eof, throws IOException
|
||||
public int readFully(byte[] bytes, int offset, int length) throws IOException {
|
||||
// return number of bytes read if positive, -1 if eof, throws IOException
|
||||
public int read(byte[] bytes, int offset, int length) throws IOException {
|
||||
if (file!=null) {
|
||||
file.readFully(bytes, offset, length);
|
||||
return file.read(bytes, offset, length);
|
||||
} else if (is!=null) {
|
||||
for ( int i=0; i<length; i++, offset++ ) {
|
||||
int c = is.read();
|
||||
if ( c < 0 )
|
||||
return -1;
|
||||
bytes[offset++] = (byte) c;
|
||||
}
|
||||
return is.read(bytes, offset, length);
|
||||
} else {
|
||||
notimplemented();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user