Mercurial > hg4j
diff src/com/tmate/hgkit/fs/DataAccess.java @ 51:9429c7bd1920 wrap-data-access
Try DataAccess to reach revision data instead of plain byte arrays
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sun, 16 Jan 2011 01:20:26 +0100 |
parents | 382cfe9463db |
children |
line wrap: on
line diff
--- a/src/com/tmate/hgkit/fs/DataAccess.java Sat Jan 15 01:41:49 2011 +0100 +++ b/src/com/tmate/hgkit/fs/DataAccess.java Sun Jan 16 01:20:26 2011 +0100 @@ -9,12 +9,20 @@ * relevant parts of DataInput, non-stream nature (seek operation), explicit check for end of data. * convenient skip (+/- bytes) * Primary goal - effective file read, so that clients don't need to care whether to call few - * distinct getInt() or readBytes(totalForFewInts) and parse themselves instead in an attempt to optimize. + * distinct getInt() or readBytes(totalForFewInts) and parse themselves instead in an attempt to optimize. + * Name: ByteSource? DataSource, DataInput, ByteInput */ public class DataAccess { public boolean isEmpty() { return true; } + public long length() { + return 0; + } + // get this instance into initial state + public void reset() throws IOException { + // nop, empty instance is always in the initial state + } // absolute positioning public void seek(long offset) throws IOException { throw new UnsupportedOperationException(); @@ -45,4 +53,17 @@ public byte readByte() throws IOException { throw new UnsupportedOperationException(); } + + // XXX decide whether may or may not change position in the DataAccess + // FIXME exception handling is not right, just for the sake of quick test + public byte[] byteArray() { + byte[] rv = new byte[(int) length()]; + try { + reset(); + readBytes(rv, 0, rv.length); + } catch (IOException ex) { + ex.printStackTrace(); + } + return rv; + } } \ No newline at end of file