1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.fastlz;
14 import static org.junit.Assert.assertTrue;
15 import static org.junit.Assert.fail;
18 import java.io.FileInputStream;
19 import java.io.FileOutputStream;
20 import java.io.IOException;
21 import java.io.InputStream;
22 import java.io.OutputStream;
23 import java.util.zip.GZIPInputStream;
24 import java.util.zip.GZIPOutputStream;
26 import org.junit.Test;
27 import org.simantics.fastlz.impl.OS;
29 public class FastLZTest1 {
32 public void testCalculateOS() {
33 OSType os = OSType.calculate();
34 assertTrue("unknown OS type", os != OSType.UNKNOWN);
38 public void testCalculateArch() {
39 ARCHType arch = ARCHType.calculate();
40 assertTrue("unknown architecture type", arch != ARCHType.UNKNOWN);
44 public void testFormOsArchSuffix() {
45 OS.formOsArchSuffix();
49 public void testInitialize() {
50 fail("Not yet implemented");
54 public void testCompress() {
55 fail("Not yet implemented");
59 public void testDecompressCluster() {
60 fail("Not yet implemented");
64 public void testDecompress() {
65 fail("Not yet implemented");
69 public void testRead() {
70 fail("Not yet implemented");
74 public void testWrite() {
75 fail("Not yet implemented");
78 public static void test() {
79 byte[] data = new byte[537520000];
83 long beginTime = System.nanoTime();
84 File snapfile = new File("d:/Loviisa080129/Loviisa080129.dir/loviisa080129.snp.gz");
85 GZIPInputStream stream = new GZIPInputStream(new FileInputStream(snapfile), 128*1024);
88 int length = stream.read(data, pos, data.length-pos);
94 long endTime = System.nanoTime();
96 System.out.println("Uncompressed size: " + pos);
97 System.out.println("GZip read: " + (endTime-beginTime)*1e-9 + "s");
98 } catch (Throwable e) {
103 Checksum cs = new CRC32();
104 cs.update(data, 0, data.length);
105 System.out.println("Checksum: " + cs.getValue());
109 File file = new File("d:/testlz.dat");
111 long beginTime = System.nanoTime();
112 OutputStream output = FastLZ.write(file);
115 long endTime = System.nanoTime();
117 System.out.println("FastLZ write: " + (endTime-beginTime)*1e-9 + "s");
120 System.out.println("FastLZ compressed size: " + file.length());
123 long beginTime = System.nanoTime();
124 InputStream input = FastLZ.read(file);
127 long endTime = System.nanoTime();
129 System.out.println("FastLZ read: " + (endTime-beginTime)*1e-9 + "s");
133 Checksum cs = new CRC32();
134 cs.update(data, 0, data.length);
135 System.out.println("Checksum: " + cs.getValue());
137 } catch(Throwable e) {
142 File snapfile = new File("d:/testgz.dat");
144 long beginTime = System.nanoTime();
145 OutputStream stream = new GZIPOutputStream(new FileOutputStream(snapfile));
148 long endTime = System.nanoTime();
150 System.out.println("GZip write: " + (endTime-beginTime)*1e-9 + "s");
151 System.out.println("GZip compressed size: " + snapfile.length());
152 } catch (Throwable e) {
158 public static void test2() {
159 File file = new File("d:/testi.flz");
161 /*OutputStream stream = write(file);
162 for(int i=0;i<100000;++i)
163 stream.write((Integer.toString(i) + "\n").getBytes());
165 InputStream stream = FastLZ.read(file);
166 byte[] b = new byte[100000];
168 for(int i=0;i<100000;++i) {
169 System.out.print((char)b[i]);
172 } catch(IOException e) {