comparison src/org/tmatesoft/hg/internal/DataAccessProvider.java @ 157:d5268ca7715b

Merged branch wrap-data-access into default for resource-friendly data access. Updated API to promote that friendliness to clients (channels, not byte[]). More exceptions
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Wed, 09 Mar 2011 05:22:17 +0100
parents src/com/tmate/hgkit/fs/DataAccessProvider.java@9429c7bd1920 src/com/tmate/hgkit/fs/DataAccessProvider.java@a3a2e5deb320
children b413b16d10a5
comparison
equal deleted inserted replaced
156:643ddec3be36 157:d5268ca7715b
84 public boolean isEmpty() { 84 public boolean isEmpty() {
85 return position + (buffer == null ? 0 : buffer.position()) >= size; 85 return position + (buffer == null ? 0 : buffer.position()) >= size;
86 } 86 }
87 87
88 @Override 88 @Override
89 public long length() {
90 return size;
91 }
92
93 @Override
94 public DataAccess reset() throws IOException {
95 seek(0);
96 return this;
97 }
98
99 @Override
89 public void seek(long offset) { 100 public void seek(long offset) {
90 assert offset >= 0; 101 assert offset >= 0;
91 // offset may not necessarily be further than current position in the file (e.g. rewind) 102 // offset may not necessarily be further than current position in the file (e.g. rewind)
92 if (buffer != null && /*offset is within buffer*/ offset >= position && (offset - position) < buffer.limit()) { 103 if (buffer != null && /*offset is within buffer*/ offset >= position && (offset - position) < buffer.limit()) {
93 buffer.position((int) (offset - position)); 104 buffer.position((int) (offset - position));
186 public boolean isEmpty() { 197 public boolean isEmpty() {
187 return bufferStartInFile + buffer.position() >= size; 198 return bufferStartInFile + buffer.position() >= size;
188 } 199 }
189 200
190 @Override 201 @Override
202 public long length() {
203 return size;
204 }
205
206 @Override
207 public DataAccess reset() throws IOException {
208 seek(0);
209 return this;
210 }
211
212 @Override
191 public void seek(long offset) throws IOException { 213 public void seek(long offset) throws IOException {
192 if (offset > size) { 214 if (offset > size) {
193 throw new IllegalArgumentException(); 215 throw new IllegalArgumentException();
194 } 216 }
195 if (offset < bufferStartInFile + buffer.limit() && offset >= bufferStartInFile) { 217 if (offset < bufferStartInFile + buffer.limit() && offset >= bufferStartInFile) {