Example usage for org.apache.commons.io FileUtils readFileToByteArray

List of usage examples for org.apache.commons.io FileUtils readFileToByteArray

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils readFileToByteArray.

Prototype

public static byte[] readFileToByteArray(File file) throws IOException 

Source Link

Document

Reads the contents of a file into a byte array.

Usage

From source file:com.t3.client.AssetTransferHandler.java

@Override
public void assetComplete(Serializable id, String name, File data) {
    byte[] assetData = null;
    try {/* ww  w  .j a v a2 s .  c  om*/
        assetData = FileUtils.readFileToByteArray(data);
    } catch (IOException ioe) {
        TabletopTool.showError("Error loading composed asset file: " + id);
        return;
    }
    Asset asset = new Asset(name, assetData);
    if (!asset.getId().equals(id)) {
        TabletopTool.showError("Received an invalid image: " + id);
        return;
    }
    // Install it into our system
    AssetManager.putAsset(asset);

    // Remove the temp file
    data.delete();
    TabletopTool.getFrame().refresh();
}

From source file:net.rptools.maptool.client.AssetTransferHandler.java

public void assetComplete(Serializable id, String name, File data) {
    byte[] assetData = null;
    try {//  w w w .ja v  a2s .  c om
        assetData = FileUtils.readFileToByteArray(data);
    } catch (IOException ioe) {
        MapTool.showError("Error loading composed asset file: " + id);
        return;
    }
    Asset asset = new Asset(name, assetData);
    if (!asset.getId().equals(id)) {
        MapTool.showError("Received an invalid image: " + id);
        return;
    }
    // Install it into our system
    AssetManager.putAsset(asset);

    // Remove the temp file
    data.delete();
    MapTool.getFrame().refresh();
}

From source file:com.igormaznitsa.zxpoly.components.RomData.java

public static RomData read(final File file) throws IOException {
    return new RomData(FileUtils.readFileToByteArray(file));
}

From source file:com.cloudant.sync.datastore.BasicDBBodyTest.java

@Before
public void setUp() throws Exception {
    jsonData = FileUtils.readFileToByteArray(new File(documentOneFile));
}

From source file:com.mirth.connect.plugins.datatypes.dicom.test.DICOMSerializerTest.java

@Test
public void testToXml2() throws Exception {
    String input = Base64/*ww  w. j  a v  a 2 s. c o  m*/
            .encodeBase64String(FileUtils.readFileToByteArray(new File("tests/test-dicom-input-2.dcm")));
    String output = FileUtils.readFileToString(new File("tests/test-dicom-output-2.xml"));
    DICOMSerializer serializer = new DICOMSerializer();
    Assert.assertEquals(output, TestUtil.prettyPrintXml(serializer.toXML(input)));
}

From source file:com.cloudant.sync.datastore.BasicDatastoreTestBase.java

@Before
public void setUp() throws Exception {
    super.setUp();
    jsonData = FileUtils.readFileToByteArray(new File(documentOneFile));
    bodyOne = new BasicDocumentBody(jsonData);

    jsonData = FileUtils.readFileToByteArray(new File(documentTwoFile));
    bodyTwo = new BasicDocumentBody(jsonData);
}

From source file:jfix.db4o.xstream.converter.BlobConverter.java

public String toString(Object obj) {
    try {//w w w . j a  v  a  2s  .  c  om
        File file = ((Blob) obj).getFile();
        if (file.exists()) {
            return new Base64Encoder().encode(FileUtils.readFileToByteArray(file));
        } else {
            return "";
        }
    } catch (Exception e) {
        throw new RuntimeException(e.getMessage(), e);
    }
}

From source file:net.nicholaswilliams.java.licensing.encryption.KeyFileUtilities.java

protected static PrivateKey readEncryptedPrivateKey(File file, char[] passphrase) throws IOException {
    return KeyFileUtilities.readEncryptedPrivateKey(FileUtils.readFileToByteArray(file), passphrase);
}

From source file:com.greenpepper.server.license.LicenceGenerator.java

private static void buildAcademic() throws Exception {
    File file = File.createTempFile("academic", ".lic");
    License license = License.academic("My School", _2006, _2006);
    LicenseManager lm = new LicenseManager(getLicenseParam());
    lm.store(license, file);//from w  ww.j a  v a  2  s. co m
    if (deleteFiles)
        file.deleteOnExit();
    System.out.println("# Academic");
    System.out.println(new String(Base64.encodeBase64(FileUtils.readFileToByteArray(file))));
    System.out.println("");
}

From source file:net.michaelpigg.xbeelib.protocol.AbstractXbeeDecoderTest.java

@BeforeTest
public void beforeTest() throws IOException {
    oneioframe = FileUtils.readFileToByteArray(new File("xbee_oneioframe.dat"));
    oneioframea = FileUtils.readFileToByteArray(new File("xbee_oneioframeparta.dat"));
    oneioframeb = FileUtils.readFileToByteArray(new File("xbee_oneioframepartb.dat"));
}