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:com.github.avarabyeu.restendpoint.serializer.json.GsonSerializer.java

@SuppressWarnings("unchecked")
@Override//w  w  w  . ja  va  2s.com
public <T> T deserialize(byte[] content, Type type) throws SerializerException {
    try {
        return (T) gson.getAdapter(com.google.gson.reflect.TypeToken.<T>get(type))
                .fromJson(ByteSource.wrap(content).asCharSource(Charsets.UTF_8).openBufferedStream());
    } catch (IOException e) {
        throw new SerializerException("Unable to serialize content", e);
    }
}

From source file:org.jclouds.googlecomputeengine.internal.GoogleComputeEngineTestModule.java

GoogleComputeEngineTestModule() {
    try {/*from ww  w .  j  ava 2s  .  c  om*/
        KeyFactory keyfactory = KeyFactory.getInstance("RSA");
        PrivateKey privateKey = keyfactory
                .generatePrivate(privateKeySpec(ByteSource.wrap(PRIVATE_KEY.getBytes(UTF_8))));
        PublicKey publicKey = keyfactory
                .generatePublic(publicKeySpec(ByteSource.wrap(PUBLIC_KEY.getBytes(UTF_8))));
        keyPair = new KeyPair(publicKey, privateKey);
        openSshKey = SshKeys.encodeAsOpenSSH(RSAPublicKey.class.cast(publicKey));
    } catch (Exception e) {
        throw propagate(e);
    }
}

From source file:org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential.java

/**
 * Instantiates a new SPNEGO credential.
 *
 * @param initToken the init token//from   w  w w.  j  a  va2  s . c om
 */
public SpnegoCredential(final byte[] initToken) {
    Assert.notNull(initToken, "The initToken cannot be null.");
    this.initToken = ByteSource.wrap(initToken);
    this.isNtlm = isTokenNtlm(this.initToken);
}

From source file:com.facebook.buck.file.WriteFile.java

@Override
public ImmutableList<Step> getBuildSteps(BuildContext context, BuildableContext buildableContext) {
    buildableContext.recordArtifact(output);
    ProjectFilesystem projectFilesystem = getProjectFilesystem();
    return ImmutableList.of(new MkdirStep(projectFilesystem, output.getParent()),
            new WriteFileStep(projectFilesystem, ByteSource.wrap(fileContents), output, executable));
}

From source file:ddf.sdk.plugin.storage.PreviewStoragePlugin.java

private ContentItem createPreviewItem(Metacard metacard) {
    ContentItem preview = new ContentItemImpl(metacard.getId(), "preview",
            ByteSource.wrap(metacard.getThumbnail()), "image/jpg", metacard.getTitle(),
            metacard.getThumbnail().length, metacard);
    metacard.setAttribute(new AttributeImpl(Metacard.DERIVED_RESOURCE_URI, preview.getUri()));
    return preview;
}

From source file:google.registry.tools.LoggingParameters.java

void configureLogging() throws IOException {
    ByteSource baseConfig = (configFile != null) ? Files.asByteSource(configFile.toFile()) : DEFAULT_LOG_CONFIG;
    if (logLevel != null) {
        configLines.add(".level = " + logLevel);
    }/*from  www.j a v a  2s. co  m*/
    // Add an extra leading newline in case base properties file does not end in a newline.
    String customProperties = "\n" + Joiner.on('\n').join(configLines);
    ByteSource logConfig = ByteSource.concat(baseConfig, ByteSource.wrap(customProperties.getBytes()));
    try (InputStream input = logConfig.openStream()) {
        LogManager.getLogManager().readConfiguration(input);
    }
}

From source file:fr.eurecom.hybris.kvs.drivers.RackspaceKvs.java

public void put(String key, byte[] value) throws IOException {
    try {/*from   w  ww.  j a v  a2  s.  com*/
        Blob blob = this.blobStore.blobBuilder(key).payload(ByteSource.wrap(value)).build();
        this.blobStore.putBlob(this.rootContainer, blob);
    } catch (Exception e) {
        throw new IOException(e);
    }
}

From source file:org.apache.isis.applib.value.Blob.java

public void writeBytesTo(final OutputStream os) throws IOException {
    ByteSource.wrap(bytes).copyTo(os);
}

From source file:org.jasig.cas.support.spnego.authentication.principal.SpnegoCredential.java

/**
 * Sets next token.// ww w.  ja  v  a  2  s . co  m
 *
 * @param nextToken the next token
 */
public void setNextToken(final byte[] nextToken) {
    this.nextToken = ByteSource.wrap(nextToken);
}

From source file:com.epam.reportportal.utils.files.ImageConverter.java

/**
 * Convert BufferedImage to input stream
 * //from w w  w  .  jav a 2  s.  c o m
 * @param image
 * @throws IOException
 */
private static ByteSource convertToInputStream(BufferedImage image) {
    ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
    try {
        ImageIO.write(image, "png", byteOutputStream);
    } catch (IOException e) {
        throw new InternalReportPortalClientException("Unable to transform file to byte array.", e);
    }
    return ByteSource.wrap(byteOutputStream.toByteArray());

}