From 652a19cf13f0a00111fa82f29b2d9ebd8a9ab1bf Mon Sep 17 00:00:00 2001 From: theli Date: Thu, 9 Jun 2005 10:52:59 +0000 Subject: [PATCH] *) adding a method to read and zip a file (needed by the filehandler) for doing gzip encoding git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@255 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/server/serverFileUtils.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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); }