-
Notifications
You must be signed in to change notification settings - Fork 22
/
EncoderThread.java
66 lines (57 loc) · 1.87 KB
/
EncoderThread.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
// EncoderThread.java -- run LZMA encoder in a separate thread
// Copyright (c)2007 Christopher League <league@contrapunctus.net>
// This is free software, but it comes with ABSOLUTELY NO WARRANTY.
// GNU Lesser General Public License 2.1 or Common Public License 1.0
package net.contrapunctus.lzma;
import SevenZip.Compression.LZMA.Encoder;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.util.concurrent.ArrayBlockingQueue;
class EncoderThread extends Thread
{
protected ArrayBlockingQueue<byte[]> q;
protected InputStream in;
protected OutputStream out;
protected Encoder enc;
protected IOException exn;
private static final PrintStream dbg = System.err;
private static final boolean DEBUG;
static {
String ds = null;
try { ds = System.getProperty("DEBUG_LzmaCoders"); }
catch(SecurityException e) { }
DEBUG = ds != null;
}
EncoderThread( OutputStream _out )
{
q = ConcurrentBufferOutputStream.newQueue();
in = ConcurrentBufferInputStream.create( q );
out = _out;
enc = new Encoder();
exn = null;
if(DEBUG) dbg.printf("%s << %s (%s)%n", this, in, q);
}
public void run( )
{
try {
enc.SetEndMarkerMode( true );
enc.SetDictionarySize( 1 << 20 );
// enc.WriteCoderProperties( out );
// 5d 00 00 10 00
if(DEBUG) dbg.printf("%s begins%n", this);
enc.Code( in, out, -1, -1, null );
if(DEBUG) dbg.printf("%s ends%n", this);
out.close( );
}
catch( IOException _exn ) {
exn = _exn;
if(DEBUG) dbg.printf("%s exception: %s%n", exn.getMessage());
}
}
public String toString( )
{
return String.format("Enc@%x", hashCode());
}
}