Mercurial > hg4j
comparison src/com/tmate/hgkit/fs/DataAccess.java @ 10:382cfe9463db
Dirstate parsing. DataAccess refactored to allow reuse and control over constants
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Sat, 25 Dec 2010 21:50:12 +0100 |
parents | |
children | 9429c7bd1920 |
comparison
equal
deleted
inserted
replaced
9:d6d2a630f4a6 | 10:382cfe9463db |
---|---|
1 /* | |
2 * Copyright (c) 2010 Artem Tikhomirov | |
3 */ | |
4 package com.tmate.hgkit.fs; | |
5 | |
6 import java.io.IOException; | |
7 | |
8 /** | |
9 * relevant parts of DataInput, non-stream nature (seek operation), explicit check for end of data. | |
10 * convenient skip (+/- bytes) | |
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. | |
13 */ | |
14 public class DataAccess { | |
15 public boolean isEmpty() { | |
16 return true; | |
17 } | |
18 // absolute positioning | |
19 public void seek(long offset) throws IOException { | |
20 throw new UnsupportedOperationException(); | |
21 } | |
22 // relative positioning | |
23 public void skip(int bytes) throws IOException { | |
24 throw new UnsupportedOperationException(); | |
25 } | |
26 // shall be called once this object no longer needed | |
27 public void done() { | |
28 // no-op in this empty implementation | |
29 } | |
30 public int readInt() throws IOException { | |
31 byte[] b = new byte[4]; | |
32 readBytes(b, 0, 4); | |
33 return b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); | |
34 } | |
35 public long readLong() throws IOException { | |
36 byte[] b = new byte[8]; | |
37 readBytes(b, 0, 8); | |
38 int i1 = b[0] << 24 | (b[1] & 0xFF) << 16 | (b[2] & 0xFF) << 8 | (b[3] & 0xFF); | |
39 int i2 = b[4] << 24 | (b[5] & 0xFF) << 16 | (b[6] & 0xFF) << 8 | (b[7] & 0xFF); | |
40 return ((long) i1) << 32 | ((long) i2 & 0xFFFFFFFF); | |
41 } | |
42 public void readBytes(byte[] buf, int offset, int length) throws IOException { | |
43 throw new UnsupportedOperationException(); | |
44 } | |
45 public byte readByte() throws IOException { | |
46 throw new UnsupportedOperationException(); | |
47 } | |
48 } |