Example usage for org.apache.wicket.util.io Streams readString

List of usage examples for org.apache.wicket.util.io Streams readString

Introduction

In this page you can find the example usage for org.apache.wicket.util.io Streams readString.

Prototype

public static String readString(final InputStream in, final CharSequence encoding) throws IOException 

Source Link

Document

Reads a string using a character encoding.

Usage

From source file:de.alpharogroup.wicket.js.addon.core.StringTextTemplate.java

License:Apache License

/**
 * Creates a new instance of a {@link StringTextTemplate}.
 * /*from   w w  w . j a v a  2  s. c o  m*/
 * @param content
 *            The content of the template.
 * @param contentType
 *            The content type.
 * @param encoding
 *            the file's encoding
 */
public StringTextTemplate(final String content, final String contentType, final String encoding) {
    super(contentType);
    final IResourceStream stream = new StringResourceStream(content, getContentType());
    try {
        if (encoding != null) {
            buffer.append(Streams.readString(stream.getInputStream(), encoding));
        } else {
            buffer.append(Streams.readString(stream.getInputStream()));
        }
    } catch (final IOException e) {
        throw new RuntimeException(e);
    } catch (final ResourceStreamNotFoundException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            stream.close();
        } catch (final IOException e) {
            LOGGER.error("" + e.getMessage(), e);
        }
    }
}

From source file:org.artifactory.common.wicket.util.WicketUtils.java

License:Open Source License

private static String readResourceNoCache(Class scope, String file) {
    InputStream inputStream = null;
    try {//from  w  ww.  ja  va 2s. c  om
        final String path = Packages.absolutePath(scope, file);
        final IResourceStream resourceStream = Application.get().getResourceSettings()
                .getResourceStreamLocator().locate(scope, path);
        inputStream = resourceStream.getInputStream();
        return Streams.readString(inputStream, "utf-8");
    } catch (ResourceStreamNotFoundException e) {
        throw new RuntimeException(String.format("Can't find resource \"%s.%s\"", scope.getName(), file), e);
    } catch (IOException e) {
        throw new RuntimeException(String.format("Can't read resource \"%s.%s\"", scope.getName(), file), e);
    } finally {
        Closeables.closeQuietly(inputStream);
    }
}

From source file:org.wicketstuff.pageserializer.common.analyze.report.d3js.D3DataFileRenderer.java

License:Apache License

private static String readTemplateFromResource(Class<?> clazz, String resourceName) {
    InputStream resourceAsStream = clazz.getResourceAsStream(resourceName);
    try {/*  w w  w. j a  v  a  2s.c  o  m*/
        return Streams.readString(resourceAsStream, "UTF-8");
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        try {
            resourceAsStream.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}