Skip to content

Commit

Permalink
fix bug issue #85 (#86)
Browse files Browse the repository at this point in the history
* fix bug issue #85

* fix bugs that not exit when -1

* fix read 0 byte from a byte array

* remove unuseful imports and code format
  • Loading branch information
jixuan1989 authored Oct 19, 2017
1 parent 3b848c3 commit 5f7b58c
Showing 1 changed file with 40 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,43 +14,53 @@
*/
public class LocalFileInput implements TSRandomAccessFileReader {

private RandomAccessFile raf;
private RandomAccessFile raf;

public LocalFileInput(String path) throws FileNotFoundException {
this.raf = new RandomAccessFile(path, "r");
}
public LocalFileInput(String path) throws FileNotFoundException {
this.raf = new RandomAccessFile(path, "r");
}

@Override
public void seek(long offset) throws IOException {
this.raf.seek(offset);
}
@Override
public void seek(long offset) throws IOException {
this.raf.seek(offset);
}

public int read() throws IOException {
return raf.read();
}
public int read() throws IOException {
return raf.read();
}

public int read(byte[] b, int off, int len) throws IOException {
return raf.read(b, off, len);
public int read(byte[] b, int off, int len) throws IOException {
int end = len + off;
int get = 1;
int total = 0;
for (int i = off; i < end; i += get) {
get = raf.read(b, i, end - i);
if (get > 0)
total += get;
else
break;
}
return total;
}

public long length() throws IOException {
return raf.length();
}
public long length() throws IOException {
return raf.length();
}

@Override
public int readInt() throws IOException {
return raf.readInt();
}
@Override
public int readInt() throws IOException {
return raf.readInt();
}

/**
* use {@code FileStreamManager} to manage all LocalFileInput
*/
public void closeFromManager() {
FileStreamManager.getInstance().close(this);
}
/**
* use {@code FileStreamManager} to manage all LocalFileInput
*/
public void closeFromManager() {
FileStreamManager.getInstance().close(this);
}

@Override
public void close() throws IOException {
raf.close();
}
@Override
public void close() throws IOException {
raf.close();
}
}

0 comments on commit 5f7b58c

Please sign in to comment.