Mercurial > hg4j
comparison src/org/tmatesoft/hg/internal/InflaterDataAccess.java @ 584:ed243b668502
Conditionally enable effective patch merge alternative for revlog reading
| author | Artem Tikhomirov <tikhomirov.artem@gmail.com> |
|---|---|
| date | Thu, 25 Apr 2013 16:08:17 +0200 |
| parents | 3c4db86e8c1f |
| children | bcbcc318f250 |
comparison
equal
deleted
inserted
replaced
| 583:47dfa0ec7e35 | 584:ed243b668502 |
|---|---|
| 14 * the terms of a license other than GNU General Public License | 14 * the terms of a license other than GNU General Public License |
| 15 * contact TMate Software at support@hg4j.com | 15 * contact TMate Software at support@hg4j.com |
| 16 */ | 16 */ |
| 17 package org.tmatesoft.hg.internal; | 17 package org.tmatesoft.hg.internal; |
| 18 | 18 |
| 19 import java.io.EOFException; | |
| 19 import java.io.IOException; | 20 import java.io.IOException; |
| 20 import java.nio.ByteBuffer; | 21 import java.nio.ByteBuffer; |
| 21 import java.util.zip.DataFormatException; | 22 import java.util.zip.DataFormatException; |
| 22 import java.util.zip.Inflater; | 23 import java.util.zip.Inflater; |
| 23 import java.util.zip.ZipException; | 24 import java.util.zip.ZipException; |
| 151 return outBuffer.get(); | 152 return outBuffer.get(); |
| 152 } | 153 } |
| 153 | 154 |
| 154 @Override | 155 @Override |
| 155 public void readBytes(byte[] b, int off, int len) throws IOException { | 156 public void readBytes(byte[] b, int off, int len) throws IOException { |
| 157 int fromBuffer; | |
| 156 do { | 158 do { |
| 157 int fromBuffer = outBuffer.remaining(); | 159 fromBuffer = outBuffer.remaining(); |
| 158 if (fromBuffer > 0) { | 160 if (fromBuffer > 0) { |
| 159 if (fromBuffer >= len) { | 161 if (fromBuffer >= len) { |
| 160 outBuffer.get(b, off, len); | 162 outBuffer.get(b, off, len); |
| 161 return; | 163 return; |
| 162 } else { | 164 } else { |
| 164 off += fromBuffer; | 166 off += fromBuffer; |
| 165 len -= fromBuffer; | 167 len -= fromBuffer; |
| 166 // fall-through | 168 // fall-through |
| 167 } | 169 } |
| 168 } | 170 } |
| 169 fillOutBuffer(); | 171 fromBuffer = fillOutBuffer(); |
| 170 } while (len > 0); | 172 } while (len > 0 && fromBuffer > 0); |
| 173 if (len > 0) { | |
| 174 // prevent hang up in this cycle if no more data is available, see Issue 25 | |
| 175 throw new EOFException(String.format("No more compressed data is available to satisfy request for %d bytes. [finished:%b, needDict:%b, needInp:%b, available:%d", len, inflater.finished(), inflater.needsDictionary(), inflater.needsInput(), super.available())); | |
| 176 } | |
| 171 } | 177 } |
| 172 | 178 |
| 173 @Override | 179 @Override |
| 174 public void readBytes(ByteBuffer buf) throws IOException { | 180 public void readBytes(ByteBuffer buf) throws IOException { |
| 175 int len = Math.min(available(), buf.remaining()); | 181 int len = Math.min(available(), buf.remaining()); |
| 218 } else { | 224 } else { |
| 219 // inflated nothing and doesn't want any more data (or no date available) - assume we're done | 225 // inflated nothing and doesn't want any more data (or no date available) - assume we're done |
| 220 assert inflater.finished(); | 226 assert inflater.finished(); |
| 221 assert toRead <= 0; | 227 assert toRead <= 0; |
| 222 break; | 228 break; |
| 223 // prevent hang up in this cycle if no more data is available, see Issue 25 | |
| 224 // throw new EOFException(String.format("No more compressed data is available to satisfy request for %d bytes. [finished:%b, needDict:%b, needInp:%b, available:%d", len, inflater.finished(), inflater.needsDictionary(), inflater.needsInput(), toRead)); | |
| 225 } | 229 } |
| 226 } | 230 } |
| 227 off += n; | 231 off += n; |
| 228 len -= n; | 232 len -= n; |
| 229 inflatedBytes += n; | 233 inflatedBytes += n; |
