Mercurial > jhg
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 50:f1db8610da62 | 51:9429c7bd1920 |
|---|---|
| 7 | 7 |
| 8 /** | 8 /** |
| 9 * relevant parts of DataInput, non-stream nature (seek operation), explicit check for end of data. | 9 * relevant parts of DataInput, non-stream nature (seek operation), explicit check for end of data. |
| 10 * convenient skip (+/- bytes) | 10 * convenient skip (+/- bytes) |
| 11 * Primary goal - effective file read, so that clients don't need to care whether to call few | 11 * Primary goal - effective file read, so that clients don't need to care whether to call few |
| 12 * distinct getInt() or readBytes(totalForFewInts) and parse themselves instead in an attempt to optimize. | 12 * distinct getInt() or readBytes(totalForFewInts) and parse themselves instead in an attempt to optimize. |
| 13 * Name: ByteSource? DataSource, DataInput, ByteInput | |
| 13 */ | 14 */ |
| 14 public class DataAccess { | 15 public class DataAccess { |
| 15 public boolean isEmpty() { | 16 public boolean isEmpty() { |
| 16 return true; | 17 return true; |
| 18 } | |
| 19 public long length() { | |
| 20 return 0; | |
| 21 } | |
| 22 // get this instance into initial state | |
| 23 public void reset() throws IOException { | |
| 24 // nop, empty instance is always in the initial state | |
| 17 } | 25 } |
| 18 // absolute positioning | 26 // absolute positioning |
| 19 public void seek(long offset) throws IOException { | 27 public void seek(long offset) throws IOException { |
| 20 throw new UnsupportedOperationException(); | 28 throw new UnsupportedOperationException(); |
| 21 } | 29 } |
| 43 throw new UnsupportedOperationException(); | 51 throw new UnsupportedOperationException(); |
| 44 } | 52 } |
| 45 public byte readByte() throws IOException { | 53 public byte readByte() throws IOException { |
| 46 throw new UnsupportedOperationException(); | 54 throw new UnsupportedOperationException(); |
| 47 } | 55 } |
| 56 | |
| 57 // XXX decide whether may or may not change position in the DataAccess | |
| 58 // FIXME exception handling is not right, just for the sake of quick test | |
| 59 public byte[] byteArray() { | |
| 60 byte[] rv = new byte[(int) length()]; | |
| 61 try { | |
| 62 reset(); | |
| 63 readBytes(rv, 0, rv.length); | |
| 64 } catch (IOException ex) { | |
| 65 ex.printStackTrace(); | |
| 66 } | |
| 67 return rv; | |
| 68 } | |
| 48 } | 69 } |
