*) 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
pull/1/head
theli 20 years ago
parent af9cd67334
commit 652a19cf13

@ -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);
}

Loading…
Cancel
Save