Example usage for com.google.common.io ByteSource wrap

List of usage examples for com.google.common.io ByteSource wrap

Introduction

In this page you can find the example usage for com.google.common.io ByteSource wrap.

Prototype

public static ByteSource wrap(byte[] b) 

Source Link

Document

Returns a view of the given byte array as a ByteSource .

Usage

From source file:org.opendaylight.controller.cluster.schema.provider.impl.YangTextSchemaSourceSerializationProxy.java

public YangTextSchemaSource getRepresentation() {
    return YangTextSchemaSource.delegateForByteSource(
            RevisionSourceIdentifier.create(name, Optional.of(revision)), ByteSource.wrap(schemaSource));
}

From source file:net.derquinse.common.io.DurableFiles.java

/**
 * Overwrites a file with the contents of a byte array.The file is sync'd before being closed.
 * @param from the bytes to write/*from  w ww .  j  a  v  a2 s .c om*/
 * @param to the destination file
 * @throws IOException if an I/O error occurs
 */
public static void write(byte[] from, File to) throws IOException {
    copy(ByteSource.wrap(from), to);
}

From source file:com.torodb.torod.db.backends.converters.array.BinaryToArrayConverter.java

@Override
public ScalarBinary fromJsonValue(JsonString value) {
    byte[] bytes = HexUtils.hex2Bytes(value.getString());
    return new ByteSourceScalarBinary(KVBinarySubtype.MONGO_GENERIC, (byte) 0, ByteSource.wrap(bytes));
}

From source file:com.android.builder.internal.packaging.zip.utils.ByteTracker.java

/**
 * Creates a new byte source by fully reading an input stream.
 * @param stream the input stream/* ww  w.  jav  a  2  s.c o  m*/
 * @return a byte source containing the cached data from the given stream
 * @throws IOException failed to read the stream
 */
public CloseableDelegateByteSource fromStream(@NonNull InputStream stream) throws IOException {
    byte[] data = ByteStreams.toByteArray(stream);
    updateUsage(data.length);
    return new CloseableDelegateByteSource(ByteSource.wrap(data), data.length) {
        @Override
        public synchronized void innerClose() throws IOException {
            super.innerClose();
            updateUsage(-sizeNoException());
        }
    };
}

From source file:com.torodb.backend.converters.json.BinaryValueToJsonConverter.java

@Override
public KvBinary toValue(String value) {
    if (!value.startsWith("\\x")) {
        throw new RuntimeException("A bytea in escape format was expected, but " + value + " was found");
    }/*from   w w w .j  a v a 2  s  .  c o m*/
    return new ByteSourceKvBinary(KvBinarySubtype.MONGO_GENERIC, (byte) 0,
            ByteSource.wrap(HexUtils.hex2Bytes(value.substring(2))));
}

From source file:com.vilt.minium.impl.debug.WindowScreenshotInteraction.java

@Override
protected void doPerform() {
    try {/*from w w  w.  j a va 2  s. c om*/
        CoreWebElements<?> coreWebElements = getSource();
        WebElementsDriver<?> webDriver = coreWebElements.as(WebElementsDriverProvider.class).webDriver();
        byte[] screenshot = webDriver.getScreenshotAs(OutputType.BYTES);
        ByteSource.wrap(screenshot).copyTo(stream);
    } catch (Exception e) {
        throw new RuntimeException(e);
    } finally {
        try {
            Closeables.close(stream, true);
        } catch (IOException e) {
        }
    }
}

From source file:com.torodb.backend.postgresql.converters.jooq.BinaryValueConverter.java

@Override
public KvBinary from(byte[] databaseObject) {
    return new ByteSourceKvBinary(KvBinarySubtype.MONGO_GENERIC, (byte) 0, ByteSource.wrap(databaseObject));
}

From source file:org.spka.cursus.publish.website.ftp.DownloadDataFiles.java

public void from(FTPClient ftp) throws IOException {
    if (!ftp.setFileType(FTP.BINARY_FILE_TYPE)) {
        throw new IllegalStateException("Unable to set mode to binary");
    }//from   ww  w  .j a  v a  2  s.c o  m

    for (String fileName : files.keySet()) {
        if (fileName.startsWith(Constants.RESULTS_DIR + "/__") && fileName.endsWith(".xml")) {
            if (files.get(fileName) == null) {
                ByteArrayOutputStream buf = new ByteArrayOutputStream();
                if (!ftp.retrieveFile(fileName, buf)) {
                    throw new IllegalStateException("Unable to retrieve " + fileName);
                }
                buf.close();
                files.put(fileName, ByteSource.wrap(buf.toByteArray()));
            }
        }
    }
}

From source file:com.github.avarabyeu.restendpoint.serializer.json.GsonSerializer.java

@Override
public <T> T deserialize(byte[] content, Class<T> clazz) throws SerializerException {
    try {//from  w  w  w.  java 2s  . c om
        return gson.fromJson(ByteSource.wrap(content).asCharSource(Charsets.UTF_8).openBufferedStream(), clazz);
    } catch (IOException e) {
        throw new SerializerException("Unable to serialize content", e);
    }
}

From source file:com.torodb.torod.db.backends.converters.json.BinaryValueToJsonConverter.java

@Override
public ScalarBinary toValue(String value) {
    if (!value.startsWith("\\x")) {
        throw new ToroImplementationException(
                "A bytea in escape format was expected, but " + value + " was found");
    }/*from   w  ww . jav a  2s.c  om*/
    return new ByteSourceScalarBinary(KVBinarySubtype.MONGO_GENERIC, (byte) 0,
            ByteSource.wrap(HexUtils.hex2Bytes(value.substring(2))));
}