Example usage for java.io ByteArrayInputStream ByteArrayInputStream

List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream

Introduction

In this page you can find the example usage for java.io ByteArrayInputStream ByteArrayInputStream.

Prototype

public ByteArrayInputStream(byte buf[]) 

Source Link

Document

Creates a ByteArrayInputStream so that it uses buf as its buffer array.

Usage

From source file:Main.java

/**
 * Some code copied from Passerelle (theirs private method)
 * @return// w  ww. ja  v a  2  s.c o  m
 */
private static InputStream openContentStream() {
    String contents = "<?xml version=\"1.0\" standalone=\"no\"?> \r\n"
            + "<!DOCTYPE entity PUBLIC \"-//UC Berkeley//DTD MoML 1//EN\" \"http://ptolemy.eecs.berkeley.edu/xml/dtd/MoML_1.dtd\"> \r\n"
            + "<entity name=\"newModel\" class=\"ptolemy.actor.TypedCompositeActor\"> \r\n"
            + "   <property name=\"_createdBy\" class=\"ptolemy.kernel.attributes.VersionAttribute\" value=\"7.0.1.4\" /> \r\n"
            + "   <property name=\"_dawnVersion\" class=\"ptolemy.kernel.attributes.VersionAttribute\" value=\""
            + System.getProperty("dawn.workbench.version") + "\" /> \r\n"
            + "   <property name=\"Director\" class=\"com.isencia.passerelle.domain.cap.Director\" > \r\n"
            + "      <property name=\"_location\" class=\"ptolemy.kernel.util.Location\" value=\"{20, 20}\" /> \r\n"
            + "   </property> \r\n" + "</entity>";
    return new ByteArrayInputStream(contents.getBytes());
}

From source file:com.seleniumtests.util.imaging.ImageProcessor.java

public static BufferedImage loadFromFile(byte[] imgData) throws IOException {
    InputStream in = new ByteArrayInputStream(imgData);
    return ImageIO.read(in);
}

From source file:com.pcms.core.util.ObjectUtil.java

public static Object deserialize(byte[] bytes) {
    ByteArrayInputStream bais = null;
    try {//from  w ww.ja  v a2 s .co m
        bais = new ByteArrayInputStream(bytes);
        ObjectInputStream ois = new ObjectInputStream(bais);
        return ois.readObject();
    } catch (Exception e) {
        LOG.error(e.getMessage());
    }
    return null;
}

From source file:com.yiji.openapi.sdk.util.Servlets.java

public static void writeResponse(HttpServletResponse response, String data) {
    OutputStream output = null;/*from  w w w.  j  a v a  2  s  .  c om*/
    InputStream input = null;
    try {
        response.setCharacterEncoding("UTF-8");
        response.setContentType(MediaType.APPLICATION_JSON_VALUE);
        output = response.getOutputStream();
        input = new ByteArrayInputStream(data.getBytes(Charset.forName("UTF-8")));
        IOUtils.copy(input, output);
        output.flush();
    } catch (Exception e) {
        throw new RuntimeException("?(flushResponse):" + e.getMessage());
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(input);
    }
}

From source file:Main.java

@SuppressWarnings("unchecked")
public static <T> T read(String input, Class<T> typeParameterClass) {
    T content = null;//  w  w w .  j  a v  a2s.  c o m
    try {
        JAXBContext jaxbContext = JAXBContext.newInstance(typeParameterClass);

        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        //jaxbUnmarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        InputStream is = new ByteArrayInputStream(input.getBytes());
        content = (T) jaxbUnmarshaller.unmarshal(is);
    } catch (JAXBException e) {
        e.printStackTrace();
    }
    return content;
}

From source file:com.jdom.util.properties.PropertiesUtil.java

public static Properties readPropertiesFile(final String string) throws IllegalArgumentException {
    InputStream is = new ByteArrayInputStream(string.getBytes());
    return readPropertiesFile(is);
}

From source file:de.tor.tribes.util.xml.JDomUtils.java

public static Document getDocument(String pDocument) throws Exception {
    return getDocument(new ByteArrayInputStream(pDocument.getBytes()));
}

From source file:Main.java

public static Document getDocument(final String xml)
        throws ParserConfigurationException, SAXException, IOException {
    final DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance();
    domFactory.setNamespaceAware(true);/*from   ww w . j  a v a  2 s  .  co m*/
    final DocumentBuilder builder = domFactory.newDocumentBuilder();
    return builder.parse(new ByteArrayInputStream(xml.getBytes("UTF-8")));
}

From source file:com.aeg.ims.ftp.SftpTestUtils.java

public static void createTestFiles(RemoteFileTemplate<LsEntry> template, final String... fileNames) {
    if (template != null) {
        final ByteArrayInputStream stream = new ByteArrayInputStream("foo".getBytes());
        template.execute(new SessionCallback<LsEntry, Void>() {

            @Override//from ww w . j  a v  a  2 s. c  o m
            public Void doInSession(Session<LsEntry> session) throws IOException {
                try {
                    session.mkdir("BriansTest");
                } catch (Exception e) {
                    assertThat(e.getMessage(), containsString("failed to create"));
                }
                for (int i = 0; i < fileNames.length; i++) {
                    stream.reset();
                    session.write(stream, "Test" + fileNames[i]);
                }
                return null;
            }
        });
    }
}

From source file:org.springframework.cloud.netflix.ribbon.apache.HttpClientUtils.java

/**
 * Creates an new {@link HttpEntity} by copying the {@link HttpEntity} from the {@link HttpResponse}.
 * This method will close the response after copying the entity.
 * @param response The response to create the {@link HttpEntity} from
 * @return A new {@link HttpEntity}/* ww w.j  a  v a  2s. com*/
 * @throws IOException thrown if there is a problem closing the response.
 */
public static HttpEntity createEntity(HttpResponse response) throws IOException {
    ByteArrayInputStream is = new ByteArrayInputStream(EntityUtils.toByteArray(response.getEntity()));
    BasicHttpEntity entity = new BasicHttpEntity();
    entity.setContent(is);
    entity.setContentLength(response.getEntity().getContentLength());
    if (CloseableHttpResponse.class.isInstance(response)) {
        ((CloseableHttpResponse) response).close();
    }
    return entity;
}