Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/FilterDataAccess.java @ 420:6c22bdc0bdfd
Respect long offsets in revlogs
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 22 Mar 2012 22:56:01 +0100 |
parents | 5e95b0da26f2 |
children | fdd7d756dea0 |
comparison
equal
deleted
inserted
replaced
419:7f136a3fa671 | 420:6c22bdc0bdfd |
---|---|
26 * @author Artem Tikhomirov | 26 * @author Artem Tikhomirov |
27 * @author TMate Software Ltd. | 27 * @author TMate Software Ltd. |
28 */ | 28 */ |
29 public class FilterDataAccess extends DataAccess { | 29 public class FilterDataAccess extends DataAccess { |
30 private final DataAccess dataAccess; | 30 private final DataAccess dataAccess; |
31 private final int offset; | 31 private final long offset; |
32 private final int length; | 32 private final int length; |
33 private int count; | 33 private int count; |
34 | 34 |
35 public FilterDataAccess(DataAccess dataAccess, int offset, int length) { | 35 public FilterDataAccess(DataAccess dataAccess, long offset, int length) { |
36 this.dataAccess = dataAccess; | 36 this.dataAccess = dataAccess; |
37 this.offset = offset; | 37 this.offset = offset; |
38 this.length = length; | 38 this.length = length; |
39 count = length; | 39 count = length; |
40 } | 40 } |
62 @Override | 62 @Override |
63 public void seek(int localOffset) throws IOException { | 63 public void seek(int localOffset) throws IOException { |
64 if (localOffset < 0 || localOffset > length) { | 64 if (localOffset < 0 || localOffset > length) { |
65 throw new IllegalArgumentException(); | 65 throw new IllegalArgumentException(); |
66 } | 66 } |
67 dataAccess.seek(offset + localOffset); | 67 dataAccess.longSeek(offset + localOffset); |
68 count = (int) (length - localOffset); | 68 count = length - localOffset; |
69 } | 69 } |
70 | 70 |
71 @Override | 71 @Override |
72 public void skip(int bytes) throws IOException { | 72 public void skip(int bytes) throws IOException { |
73 int newCount = count - bytes; | 73 int newCount = count - bytes; |
89 public byte readByte() throws IOException { | 89 public byte readByte() throws IOException { |
90 if (count <= 0) { | 90 if (count <= 0) { |
91 throw new IOException(String.format("Underflow. Bytes left: %d. FilterDA[offset: %d, length: %d]", count, offset, length)); | 91 throw new IOException(String.format("Underflow. Bytes left: %d. FilterDA[offset: %d, length: %d]", count, offset, length)); |
92 } | 92 } |
93 if (count == length) { | 93 if (count == length) { |
94 dataAccess.seek(offset); | 94 dataAccess.longSeek(offset); |
95 } | 95 } |
96 count--; | 96 count--; |
97 return dataAccess.readByte(); | 97 return dataAccess.readByte(); |
98 } | 98 } |
99 | 99 |
104 } | 104 } |
105 if (count <= 0 || len > count) { | 105 if (count <= 0 || len > count) { |
106 throw new IOException(String.format("Underflow. Bytes left: %d, asked to read %d. FilterDA[offset: %d, length: %d]", count, len, offset, length)); | 106 throw new IOException(String.format("Underflow. Bytes left: %d, asked to read %d. FilterDA[offset: %d, length: %d]", count, len, offset, length)); |
107 } | 107 } |
108 if (count == length) { | 108 if (count == length) { |
109 dataAccess.seek(offset); | 109 dataAccess.longSeek(offset); |
110 } | 110 } |
111 dataAccess.readBytes(b, off, len); | 111 dataAccess.readBytes(b, off, len); |
112 count -= len; | 112 count -= len; |
113 } | 113 } |
114 | 114 |