Mercurial > jhg
comparison src/com/tmate/hgkit/fs/DataAccessProvider.java @ 23:6f9aca1a97be
Severe defect in buffer wrap on seek
author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
---|---|
date | Thu, 06 Jan 2011 03:30:43 +0100 |
parents | 382cfe9463db |
children | 71a9ba42cee8 |
comparison
equal
deleted
inserted
replaced
22:603806cd2dc6 | 23:6f9aca1a97be |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 2010 Artem Tikhomirov | 2 * Copyright (c) 2010, 2011 Artem Tikhomirov |
3 */ | 3 */ |
4 package com.tmate.hgkit.fs; | 4 package com.tmate.hgkit.fs; |
5 | 5 |
6 import java.io.File; | 6 import java.io.File; |
7 import java.io.FileInputStream; | 7 import java.io.FileInputStream; |
108 return bufferStartInFile + buffer.position() >= size; | 108 return bufferStartInFile + buffer.position() >= size; |
109 } | 109 } |
110 | 110 |
111 @Override | 111 @Override |
112 public void seek(long offset) throws IOException { | 112 public void seek(long offset) throws IOException { |
113 if (offset > size) { | |
114 throw new IllegalArgumentException(); | |
115 } | |
113 if (offset < bufferStartInFile + buffer.limit() && offset >= bufferStartInFile) { | 116 if (offset < bufferStartInFile + buffer.limit() && offset >= bufferStartInFile) { |
114 buffer.position((int) (offset - bufferStartInFile)); | 117 buffer.position((int) (offset - bufferStartInFile)); |
115 } else { | 118 } else { |
116 // out of current buffer, invalidate it (force re-read) | 119 // out of current buffer, invalidate it (force re-read) |
117 // XXX or ever re-read it right away? | 120 // XXX or ever re-read it right away? |
128 if (newPos >= 0 && newPos < buffer.limit()) { | 131 if (newPos >= 0 && newPos < buffer.limit()) { |
129 // no need to move file pointer, just rewind/seek buffer | 132 // no need to move file pointer, just rewind/seek buffer |
130 buffer.position(newPos); | 133 buffer.position(newPos); |
131 } else { | 134 } else { |
132 // | 135 // |
133 seek(fileChannel.position()+ bytes); | 136 seek(bufferStartInFile + newPos); |
134 } | 137 } |
135 } | 138 } |
136 | 139 |
137 private boolean fill() throws IOException { | 140 private boolean fill() throws IOException { |
138 if (!buffer.hasRemaining()) { | 141 if (!buffer.hasRemaining()) { |