Author: toad
Date: 2008-11-22 23:09:26 +0000 (Sat, 22 Nov 2008)
New Revision: 23822
Modified:
trunk/freenet/src/freenet/support/compress/LZMACompressor.java
Log:
Only count if need to count
Modified: trunk/freenet/src/freenet/support/compress/LZMACompressor.java
===================================================================
--- trunk/freenet/src/freenet/support/compress/LZMACompressor.java
2008-11-22 21:29:27 UTC (rev 23821)
+++ trunk/freenet/src/freenet/support/compress/LZMACompressor.java
2008-11-22 23:09:26 UTC (rev 23822)
@@ -25,10 +25,17 @@
public Bucket compress(Bucket data, BucketFactory bf, long
maxReadLength, long maxWriteLength) throws IOException,
CompressionOutputSizeException {
Bucket output;
output = bf.makeBucket(maxWriteLength);
- if(Logger.shouldLog(Logger.MINOR, this))
+ boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ if(logMINOR)
Logger.minor(this, "Compressing "+data+" size
"+data.size()+" to new bucket "+output);
- CountedInputStream is = new CountedInputStream(new
BufferedInputStream(data.getInputStream()));
- CountedOutputStream os = new CountedOutputStream(new
BufferedOutputStream(output.getOutputStream()));
+ InputStream is = new BufferedInputStream(data.getInputStream());
+ OutputStream os = new
BufferedOutputStream(output.getOutputStream());
+ CountedInputStream cis = null;
+ CountedOutputStream cos = null;
+ if(logMINOR) {
+ is = cis = new CountedInputStream(is);
+ os = cos = new CountedOutputStream(os);
+ }
Encoder encoder = new Encoder();
encoder.SetEndMarkerMode( true );
encoder.SetDictionarySize( 1 << 20 );
@@ -36,8 +43,8 @@
// 5d 00 00 10 00
encoder.Code( is, os, maxReadLength, maxWriteLength, null );
os.close();
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this, "Output: "+output+" size
"+output.size()+" read "+is.count()+" written "+os.written());
+ if(logMINOR)
+ Logger.minor(this, "Output: "+output+" size
"+output.size()+" read "+cis.count()+" written "+cos.written());
return output;
}
@@ -47,14 +54,21 @@
output = preferred;
else
output = bf.makeBucket(maxLength);
- if(Logger.shouldLog(Logger.MINOR, this))
+ boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
+ if(logMINOR)
Logger.minor(this, "Decompressing "+data+" size
"+data.size()+" to new bucket "+output);
- CountedInputStream is = new CountedInputStream(new
BufferedInputStream(data.getInputStream()));
- CountedOutputStream os = new CountedOutputStream(new
BufferedOutputStream(output.getOutputStream()));
+ CountedInputStream cis = null;
+ CountedOutputStream cos = null;
+ InputStream is = new BufferedInputStream(data.getInputStream());
+ OutputStream os = new
BufferedOutputStream(output.getOutputStream());
+ if(logMINOR) {
+ is = cis = new CountedInputStream(is);
+ os = cos = new CountedOutputStream(os);
+ }
decompress(is, os, maxLength, maxCheckSizeLength);
os.close();
- if(Logger.shouldLog(Logger.MINOR, this))
- Logger.minor(this, "Output: "+output+" size
"+output.size()+" read "+is.count()+" written "+os.written());
+ if(logMINOR)
+ Logger.minor(this, "Output: "+output+" size
"+output.size()+" read "+cis.count()+" written "+cos.written());
return output;
}
_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs