view src/main/java/alice/test/codesegment/remote/compress/StartTestCompress.java @ 591:25fe2f78ac40 dispose

add remote compress test
author Nozomi Teruya <e125769@ie.u-ryukyu.ac.jp>
date Wed, 10 Feb 2016 17:34:20 +0900
parents src/main/java/alice/test/codesegment/local/compress/StartTestCompress.java@301baf61faf1
children 10b1235df119
line wrap: on
line source

package alice.test.codesegment.remote.compress;

import alice.codesegment.CodeSegment;
import javassist.bytecode.ByteArray;

import java.io.*;

/**
 * Created by e125769 on 2/9/16.
 */
public class StartTestCompress extends CodeSegment{
    @Override
    public void run() {
        System.out.println("run StartCodeSegment");

        byte[] bytes = new byte[0];
        try {
            bytes = readFileToByte("AliceText.txt");
        } catch (Exception e) {
            e.printStackTrace();
        }

        TestCompress cs = new TestCompress(100);

        long time = System.currentTimeMillis();
        ods.put("local", "time", time);
        ods.put("compressedremote", "data", bytes);
    }

    private byte[] readFileToByte(String filePath) throws Exception {
        byte[] b = new byte[1];
        FileInputStream fis = new FileInputStream(filePath);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        while (fis.read(b) > 0) {
            baos.write(b);
        }
        baos.close();
        fis.close();
        b = baos.toByteArray();

        return b;
    }

}