Example usage for com.liferay.portal.kernel.io.unsync UnsyncByteArrayOutputStream toByteArray

List of usage examples for com.liferay.portal.kernel.io.unsync UnsyncByteArrayOutputStream toByteArray

Introduction

In this page you can find the example usage for com.liferay.portal.kernel.io.unsync UnsyncByteArrayOutputStream toByteArray.

Prototype

public byte[] toByteArray() 

Source Link

Usage

From source file:com.liferay.configuration.admin.web.internal.exporter.ConfigurationExporter.java

License:Open Source License

public static byte[] getPropertiesAsBytes(Dictionary properties) throws Exception {

    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

    ConfigurationHandler.write(unsyncByteArrayOutputStream, properties);

    return unsyncByteArrayOutputStream.toByteArray();
}

From source file:com.liferay.petra.log4j.Log4JUtil.java

License:Open Source License

/**
 * @see com.liferay.portal.util.FileImpl#getBytes(InputStream, int, boolean)
 *///  ww  w  . j  ava 2  s . co  m
private static byte[] _getBytes(InputStream inputStream) throws IOException {

    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

    StreamUtil.transfer(inputStream, unsyncByteArrayOutputStream, -1, true);

    return unsyncByteArrayOutputStream.toByteArray();
}

From source file:com.liferay.util.SerializableUtil.java

License:Open Source License

public static byte[] serialize(Object object) {
    ObjectOutputStream objectOutputStream = null;

    UnsyncByteArrayOutputStream unsyncByteArrayOutputStream = new UnsyncByteArrayOutputStream();

    try {/*  w ww. j av a  2  s.  c o  m*/
        objectOutputStream = new ObjectOutputStream(unsyncByteArrayOutputStream);

        objectOutputStream.writeObject(object);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        StreamUtil.cleanUp(objectOutputStream);
    }

    return unsyncByteArrayOutputStream.toByteArray();
}

From source file:com.liferay.util.transport.MulticastDatagramHandler.java

License:Open Source License

protected byte[] getUnzippedBytes(byte[] bytes) throws Exception {
    InputStream is = new GZIPInputStream(new UnsyncByteArrayInputStream(bytes));
    UnsyncByteArrayOutputStream ubaos = new UnsyncByteArrayOutputStream(bytes.length);

    byte[] buffer = new byte[1500];

    int c = 0;/*from w ww . j  ava  2s  . c  o m*/

    while (true) {
        if (c == -1) {
            break;
        }

        c = is.read(buffer, 0, 1500);

        if (c != -1) {
            ubaos.write(buffer, 0, c);
        }
    }

    is.close();

    ubaos.flush();
    ubaos.close();

    return ubaos.toByteArray();
}