diff src/org/tmatesoft/hg/internal/InflaterDataAccess.java @ 421:fdd7d756dea0 v0.8.5

Allow IOException from DataAccess methods for subclasses with non-trivial implementations, to avoid exception dumps when inapropriate
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 22 Mar 2012 23:09:11 +0100
parents 6c22bdc0bdfd
children 9c9c442b5f2e
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/InflaterDataAccess.java	Thu Mar 22 22:56:01 2012 +0100
+++ b/src/org/tmatesoft/hg/internal/InflaterDataAccess.java	Thu Mar 22 23:09:11 2012 +0100
@@ -67,50 +67,45 @@
 	}
 	
 	@Override
-	protected int available() {
+	protected int available() throws IOException {
 		return length() - decompressedPos;
 	}
 	
 	@Override
-	public boolean isEmpty() {
+	public boolean isEmpty() throws IOException {
 		// can't use super.available() <= 0 because even when 0 < super.count < 6(?)
 		// decompressedPos might be already == length() 
 		return available() <= 0;
 	}
 	
 	@Override
-	public int length() {
+	public int length() throws IOException {
 		if (decompressedLength != -1) {
 			return decompressedLength;
 		}
 		decompressedLength = 0; // guard to avoid endless loop in case length() would get invoked from below. 
 		int c = 0;
-		try {
-			int oldPos = decompressedPos;
-			byte[] dummy = new byte[buffer.length];
-			int toRead;
-			while ((toRead = super.available()) > 0) {
-				if (toRead > buffer.length) {
-					toRead = buffer.length;
+		int oldPos = decompressedPos;
+		byte[] dummy = new byte[buffer.length];
+		int toRead;
+		while ((toRead = super.available()) > 0) {
+			if (toRead > buffer.length) {
+				toRead = buffer.length;
+			}
+			super.readBytes(buffer, 0, toRead);
+			inflater.setInput(buffer, 0, toRead);
+			try {
+				while (!inflater.needsInput()) {
+					c += inflater.inflate(dummy, 0, dummy.length);
 				}
-				super.readBytes(buffer, 0, toRead);
-				inflater.setInput(buffer, 0, toRead);
-				try {
-					while (!inflater.needsInput()) {
-						c += inflater.inflate(dummy, 0, dummy.length);
-					}
-				} catch (DataFormatException ex) {
-					throw new HgBadStateException(ex);
-				}
+			} catch (DataFormatException ex) {
+				throw new HgBadStateException(ex);
 			}
-			decompressedLength = c + oldPos;
-			reset();
-			seek(oldPos);
-			return decompressedLength;
-		} catch (IOException ex) {
-			decompressedLength = -1; // better luck next time?
-			throw new HgBadStateException(ex); // XXX perhaps, checked exception
 		}
+		decompressedLength = c + oldPos;
+		reset();
+		seek(oldPos);
+		return decompressedLength;
 	}
 	
 	@Override