Example usage for com.google.common.io Resources toByteArray

List of usage examples for com.google.common.io Resources toByteArray

Introduction

In this page you can find the example usage for com.google.common.io Resources toByteArray.

Prototype

public static byte[] toByteArray(URL url) throws IOException 

Source Link

Document

Reads all bytes from a URL into a byte array.

Usage

From source file:org.isisaddons.module.pdf.fixture.dom.templates.CustomerConfirmation.java

@PostConstruct
public void init() throws IOException {
    pdfAsBytes = Resources.toByteArray(Resources.getResource(this.getClass(), "CustomerConfirmation.pdf"));
}

From source file:common.CustomAssets.java

@Override
public void configure(Env env, Config conf, Binder binder) throws Throwable {
    env.router().assets("/favicon.ico", "/assets/permanent/favicon-6022c3e42d.ico");

    Config config = ConfigFactory.parseResources("assets.conf");
    AssetCompiler compiler = new AssetCompiler(config);
    BiFunction<String, String, String> url;
    String fbAppId = conf.getString("application.fbAppId");
    if (env.name().equals("dev")) {
        url = (type, raw) -> "/assets-dev/" + type + raw;
        env.router().assets("/assets-dev/**");
        env.router().assets("/assets/**");
    } else {//from w  w w.jav  a 2  s  .com
        byte[] manifest = Resources.toByteArray(CustomAssets.class.getResource("/assets/manifest.json"));
        Map<String, Any> map = JsonIterator.deserialize(manifest).asMap();
        url = (type, raw) -> "/assets/" + type + "/" + Objects.requireNonNull(map.get(raw.substring(1)),
                "No fingerprinted version of " + raw + ", only has: " + map.keySet());
        env.router().assets("/assets/**");
    }
    // key, style, key, script
    List<String> keyValue = new ArrayList<>(4 * compiler.fileset().size());
    for (String fileset : compiler.fileset()) {
        keyValue.add(fileset + CustomAssets._STYLES);
        keyValue.add(styles(url, compiler, fileset));
        keyValue.add(fileset + CustomAssets._SCRIPTS);
        keyValue.add(scripts(url, compiler, fileset));
    }
    env.router().before((req, rsp) -> {
        for (int i = 0; i < keyValue.size() / 2; ++i) {
            String key = keyValue.get(2 * i);
            String value = keyValue.get(2 * i + 1);
            req.set(key, value);
        }
        req.set(FB_APP_ID, fbAppId);
    });
}

From source file:io.divolte.server.BaseEventHandler.java

public BaseEventHandler(final IncomingRequestProcessingPool processingPool) {
    this.processingPool = Objects.requireNonNull(processingPool);

    try {/*from  w ww . j  a v  a 2 s . c  o m*/
        this.transparentImage = ByteBuffer
                .wrap(Resources.toByteArray(Resources.getResource("transparent1x1.gif"))).asReadOnlyBuffer();
    } catch (final IOException e) {
        // Should throw something more specific than this.
        throw new RuntimeException("Could not load transparent image resource.", e);
    }
}

From source file:org.isisaddons.module.excel.dom.util.ExcelFileBlobConverter.java

private byte[] readBytes(URL resource) {

    try {//from w  ww .j  a v a  2s .  co m
        bytes = Resources.toByteArray(resource);
    } catch (IOException e) {
        throw new IllegalArgumentException("Could not read from resource: " + resource);
    }
    return bytes;
}

From source file:org.glowroot.weaving.MixinTypeBase.java

public static MixinType from(Mixin mixin, Class<?> implementation) throws IOException {
    MixinType.Builder builder = MixinType.builder();
    builder.addTargets(mixin.value());//from   w  ww .  ja v a2 s . com
    builder.implementation(Type.getType(implementation));
    for (Class<?> iface : implementation.getInterfaces()) {
        builder.addInterfaces(Type.getType(iface));
    }
    String initMethodName = null;
    for (Method method : implementation.getDeclaredMethods()) {
        if (method.getAnnotation(MixinInit.class) != null) {
            if (initMethodName != null) {
                logger.error("mixin has more than one @MixinInit: {}", implementation.getName());
                continue;
            }
            if (method.getParameterTypes().length > 0) {
                logger.error("@MixinInit method cannot have any parameters: {}", implementation.getName());
                continue;
            }
            if (method.getReturnType() != void.class) {
                logger.warn("@MixinInit method must return void: {}", implementation.getName());
                continue;
            }
            initMethodName = method.getName();
        }
    }
    builder.initMethodName(initMethodName);
    ClassLoader loader = implementation.getClassLoader();
    String resourceName = implementation.getName().replace('.', '/') + ".class";
    URL url;
    if (loader == null) {
        url = ClassLoader.getSystemResource(resourceName);
    } else {
        url = loader.getResource(resourceName);
    }
    checkNotNull(url, "Could not find resource: %s", resourceName);
    builder.implementationBytes(Resources.toByteArray(url));
    return builder.build();
}

From source file:eu.redzoo.article.planetcassandra.reactive.service.callback.ClassicHotelService.java

public ClassicHotelService(Session session) throws IOException {
    this.session = session;
    defaultPicture = Resources.toByteArray(Resources.getResource("error.jpg"));
    preparedSelectStmt = session.prepare(
            "select id, name, description, classification, picture_uri, room_ids from hotels where id = ?");
    preparedSelectStmt.setConsistencyLevel(ConsistencyLevel.QUORUM);
}

From source file:com.sonatype.nexus.repository.nuget.internal.odata.ODataTemplates.java

private static String load(final String name) {
    try {//w ww  .  j  av a 2 s. c om
        return new String(Resources.toByteArray(ODataTemplates.class.getResource(name)), "UTF-8");
    } catch (final IOException e) {
        throw new IllegalArgumentException(e.getMessage());
    }
}

From source file:org.isisaddons.module.docx.dom.IoHelper.java

public ByteArrayInputStream asBais(final String fileName) throws IOException {
    final URL fileUrl = asUrl(fileName);
    return new ByteArrayInputStream(Resources.toByteArray(fileUrl));
}

From source file:services.docx.NotaServiceDocx.java

@PostConstruct
public void init() throws IOException, LoadTemplateException {
    final byte[] bytes = Resources.toByteArray(Resources.getResource(this.getClass(), "nota.docx"));
    wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes));
}

From source file:services.docx.MemoServiceDocx.java

@PostConstruct
public void init() throws IOException, LoadTemplateException {
    final byte[] bytes = Resources.toByteArray(Resources.getResource(this.getClass(), "memo.docx"));
    wordprocessingMLPackage = docxService.loadPackage(new ByteArrayInputStream(bytes));
}