Skip to content
Browse files

exceptions now transferred from DecoderThread to LzmaInputStream

  • Loading branch information...
1 parent 308e33c commit 65b06e3a9202eaa4feaad1f657df6f90fc3acf3d @league committed Sep 16, 2009
View
25 net/contrapunctus/lzma/ApiDriftTest.java
@@ -5,6 +5,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.concurrent.ArrayBlockingQueue;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -56,4 +57,28 @@
RoundTripTest.main(new String[0]);
RoundTripTest.main(new String[] {"build.xml"});
}
+
+ @Test public void strings()
+ {
+ ArrayBlockingQueue<byte[]> q =
+ ConcurrentBufferOutputStream.newQueue();
+ // ConcurrentBufferInputStream
+ InputStream is = ConcurrentBufferInputStream.create(q);
+ System.out.println(is);
+ // ConcurrentBufferOutputStream
+ OutputStream os = ConcurrentBufferOutputStream.create(q);
+ System.out.println(os);
+ // DecoderThread
+ Thread th = new DecoderThread(is);
+ System.out.println(th);
+ // EncoderThread
+ th = new EncoderThread(os, 0, 0);
+ System.out.println(th);
+ // LzmaInputStream
+ is = new LzmaInputStream(is);
+ System.out.println(is);
+ // LzmaOutputStream
+ os = new LzmaOutputStream(os);
+ System.out.println(os);
+ }
}
View
5 net/contrapunctus/lzma/ConcurrentBufferOutputStream.java
@@ -76,9 +76,4 @@ public void close( ) throws IOException
byte b[] = new byte[0]; // sentinel
guarded_put( b );
}
-
- public String toString( )
- {
- return String.format("cbOut@%x", hashCode());
- }
}
View
16 net/contrapunctus/lzma/DecoderThread.java
@@ -79,11 +79,23 @@ public void run( )
dec.Code( in, out, outSize );
if(DEBUG) dbg.printf("%s ends%n", this);
in.close( ); //?
- out.close( );
}
catch( IOException _exn ) {
exn = _exn;
- if(DEBUG) dbg.printf("%s exception: %s%n", exn.getMessage());
+ if(DEBUG) dbg.printf("%s exception: %s%n", this, exn.getMessage());
+ }
+ // close either way, so listener can unblock
+ try {
+ out.close( );
+ }
+ catch( IOException _exn ) {
+ }
+ }
+
+ public void maybeThrow() throws IOException
+ {
+ if(exn != null) {
+ throw exn;
}
}
View
25 net/contrapunctus/lzma/ExceptionTest.java
@@ -0,0 +1,25 @@
+package net.contrapunctus.lzma;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import org.junit.Test;
+
+public class ExceptionTest
+{
+ private void readLzma(byte[] bs) throws IOException
+ {
+ ByteArrayInputStream bais = new ByteArrayInputStream(bs);
+ LzmaInputStream lis = new LzmaInputStream(bais);
+ int x = lis.read();
+ }
+
+ @Test(timeout = 5000, expected = IOException.class) public void truncatedLzma() throws IOException
+ {
+ readLzma(new byte[] { 0x5d, 0x00, 0x00 });
+ }
+
+ @Test(timeout = 5000, expected = IOException.class) public void truncatedLzma2() throws IOException
+ {
+ readLzma(DecoderThread.props);
+ }
+}
View
14 net/contrapunctus/lzma/LzmaInputStream.java
@@ -33,6 +33,20 @@ public LzmaInputStream( InputStream _in )
dth.start( );
}
+ public int read() throws IOException
+ {
+ int k = in.read();
+ dth.maybeThrow();
+ return k;
+ }
+
+ public int read(byte[] b, int off, int len) throws IOException
+ {
+ int k = in.read(b, off, len);
+ dth.maybeThrow();
+ return k;
+ }
+
public void close( ) throws IOException
{
if(DEBUG) dbg.printf("%s closed%n", this);

0 comments on commit 65b06e3

Please sign in to comment.
Something went wrong with that request. Please try again.