Skip to content

Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance

*) adding a method to read and zip a file (needed by the filehandler) for doing gzip encoding

theli652a19cf13f0
diff --git a/source/de/anomic/server/serverFileUtils.java b/source/de/anomic/server/serverFileUtils.java
index b4da479d0..e6500ac55 100644
--- a/source/de/anomic/server/serverFileUtils.java
+++ b/source/de/anomic/server/serverFileUtils.java
@@ -48,6 +48,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.zip.GZIPOutputStream;
public final class serverFileUtils {
@@ -111,6 +112,21 @@ public final class serverFileUtils {
return buffer;
}
+ public static byte[] readAndZip(File source) throws IOException {
+ ByteArrayOutputStream byteOut = null;
+ GZIPOutputStream zipOut = null;
+ try {
+ byteOut = new ByteArrayOutputStream((int)(source.length()/2));
+ zipOut = new GZIPOutputStream(byteOut);
+ copy(source,zipOut);
+ zipOut.close();
+ return byteOut.toByteArray();
+ } finally {
+ if (zipOut != null) try { zipOut.close(); } catch (Exception e) {}
+ if (byteOut != null) try { byteOut.close(); } catch (Exception e) {}
+ }
+ }
+
public static void write(byte[] source, OutputStream dest) throws IOException {
copy(new ByteArrayInputStream(source), dest);
}