/******************************************************************************* * Copyright (c) 2007, 2010 Association for Decentralized Information Management * in Industry THTH ry. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * VTT Technical Research Centre of Finland - initial API and implementation *******************************************************************************/ package org.simantics.fastlz; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.zip.GZIPInputStream; import java.util.zip.GZIPOutputStream; import org.junit.Test; import org.simantics.fastlz.impl.OS; public class FastLZTest1 { @Test public void testCalculateOS() { OSType os = OSType.calculate(); assertTrue("unknown OS type", os != OSType.UNKNOWN); } @Test public void testCalculateArch() { ARCHType arch = ARCHType.calculate(); assertTrue("unknown architecture type", arch != ARCHType.UNKNOWN); } @Test public void testFormOsArchSuffix() { OS.formOsArchSuffix(); } @Test public void testInitialize() { fail("Not yet implemented"); } @Test public void testCompress() { fail("Not yet implemented"); } @Test public void testDecompressCluster() { fail("Not yet implemented"); } @Test public void testDecompress() { fail("Not yet implemented"); } @Test public void testRead() { fail("Not yet implemented"); } @Test public void testWrite() { fail("Not yet implemented"); } public static void test() { byte[] data = new byte[537520000]; while(true) { try { long beginTime = System.nanoTime(); File snapfile = new File("d:/Loviisa080129/Loviisa080129.dir/loviisa080129.snp.gz"); GZIPInputStream stream = new GZIPInputStream(new FileInputStream(snapfile), 128*1024); int pos = 0; while(true) { int length = stream.read(data, pos, data.length-pos); if(length <= 0) break; pos += length; } stream.close(); long endTime = System.nanoTime(); System.out.println("Uncompressed size: " + pos); System.out.println("GZip read: " + (endTime-beginTime)*1e-9 + "s"); } catch (Throwable e) { e.printStackTrace(); } /*{ Checksum cs = new CRC32(); cs.update(data, 0, data.length); System.out.println("Checksum: " + cs.getValue()); }*/ try { File file = new File("d:/testlz.dat"); { long beginTime = System.nanoTime(); OutputStream output = FastLZ.write(file); output.write(data); output.close(); long endTime = System.nanoTime(); System.out.println("FastLZ write: " + (endTime-beginTime)*1e-9 + "s"); } System.out.println("FastLZ compressed size: " + file.length()); { long beginTime = System.nanoTime(); InputStream input = FastLZ.read(file); input.read(data); input.close(); long endTime = System.nanoTime(); System.out.println("FastLZ read: " + (endTime-beginTime)*1e-9 + "s"); } /*{ Checksum cs = new CRC32(); cs.update(data, 0, data.length); System.out.println("Checksum: " + cs.getValue()); }*/ } catch(Throwable e) { e.printStackTrace(); } try { File snapfile = new File("d:/testgz.dat"); long beginTime = System.nanoTime(); OutputStream stream = new GZIPOutputStream(new FileOutputStream(snapfile)); stream.write(data); stream.close(); long endTime = System.nanoTime(); System.out.println("GZip write: " + (endTime-beginTime)*1e-9 + "s"); System.out.println("GZip compressed size: " + snapfile.length()); } catch (Throwable e) { e.printStackTrace(); } } } public static void test2() { File file = new File("d:/testi.flz"); try { /*OutputStream stream = write(file); for(int i=0;i<100000;++i) stream.write((Integer.toString(i) + "\n").getBytes()); */ InputStream stream = FastLZ.read(file); byte[] b = new byte[100000]; stream.read(b); for(int i=0;i<100000;++i) { System.out.print((char)b[i]); } stream.close(); } catch(IOException e) { e.printStackTrace(); } } }