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:ID.java

public static void main(String[] args) throws IOException, ClassNotFoundException {
    ID id = new ID();
    List employees = new ArrayList();
    employees.add(new Employee("A", id));
    employees.add(new Employee("B", id));
    employees.add(new Employee("C", id));
    System.out.println("employees: " + employees);
    ByteArrayOutputStream buf1 = new ByteArrayOutputStream();
    ObjectOutputStream o1 = new ObjectOutputStream(buf1);
    o1.writeObject(employees);/*  w w w  .  j  ava  2s .  c  om*/
    o1.writeObject(employees);

    ByteArrayOutputStream buf2 = new ByteArrayOutputStream();
    ObjectOutputStream o2 = new ObjectOutputStream(buf2);
    o2.writeObject(employees);

    ObjectInputStream in1 = new ObjectInputStream(new ByteArrayInputStream(buf1.toByteArray()));
    ObjectInputStream in2 = new ObjectInputStream(new ByteArrayInputStream(buf2.toByteArray()));
    List emp1 = (List) in1.readObject(), emp2 = (List) in1.readObject(), emp3 = (List) in2.readObject();
    System.out.println("emp1: " + emp1);
    System.out.println("emp2: " + emp2);
    System.out.println("emp3: " + emp3);
}

From source file:com.igalia.metamail.Main.java

public static void main(String[] args) {
    try {/* ww w.j a  va 2 s  .c  om*/
        String filename = "../enron-importer/data/maildir/lay-k/sent/1.";
        byte[] body = FileUtils.readFileToByteArray(new File(filename));
        InputStream input = new ByteArrayInputStream(body);
        Session s = Session.getDefaultInstance(new Properties());

        MailRecord mail = MailRecord.create(s, input);
        System.out.println("To: " + mail.getTo());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (MessagingException e) {
        e.printStackTrace();
    }
}

From source file:EchoFilterTest.java

public static void main(String[] args) {

    // load the sound
    SimpleSoundPlayer sound = new SimpleSoundPlayer("../sounds/voice.wav");

    // create the sound stream
    InputStream is = new ByteArrayInputStream(sound.getSamples());

    // create an echo with a 11025-sample buffer
    // (1/4 sec for 44100Hz sound) and a 60% decay
    EchoFilter filter = new EchoFilter(11025, .6f);

    // create the filtered sound stream
    is = new FilteredSoundStream(is, filter);

    // play the sound
    sound.play(is);/*ww  w.ja  va 2s. c o  m*/

    // due to bug in Java Sound, explicitly exit the VM.
    System.exit(0);
}

From source file:at.orz.arangodb.sandbox.PostChunkTest.java

/**
 * @param args/* w  ww. j a v  a 2  s .c om*/
 */
public static void main(String[] args) throws Exception {

    HttpClient client = new DefaultHttpClient();

    HttpPost post = new HttpPost(
            "http://arango-test-server:9999/_api/import?collection=test1&createCollection=true&type=documents");
    //post.setEntity(new StringEntity("{\"xx\": \"123\"}{\"xx\": \"456\"}"));
    InputStreamEntity entity = new InputStreamEntity(
            new ByteArrayInputStream("{\"xx\": \"123\"}{\"xx\": \"456\"}".getBytes()), 26);
    entity.setChunked(true);
    post.setEntity(entity);

    HttpResponse res = client.execute(post);

    System.out.println(res.getStatusLine());

    post.releaseConnection();
}

From source file:com.metamug.mtg.s3.uploader.S3Uploader.java

public static void main(String[] args) {
    String path = args[0];//www.j  a v  a2s.c  o m
    String uri = args[1];
    String url = "";
    if (StringUtils.isNotBlank(path)) {
        byte[] buffer = getBytes(path);
        url = upload(new ByteArrayInputStream(buffer), buffer.length, uri);
    }
    System.out.println("");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InputStream is = new FileInputStream("test.xml");
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();

    Document oldDoc = builder.parse(is);
    Node oldRoot = oldDoc.getDocumentElement();
    Document newDoc = builder.newDocument();
    Element newRoot = newDoc.createElement("newroot");
    newDoc.appendChild(newRoot);//from   ww  w  .  j  a  v a 2s.co m
    newRoot.appendChild(newDoc.importNode(oldRoot, true));

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    DOMSource domSource = new DOMSource(newDoc);
    Writer writer = new OutputStreamWriter(out);
    StreamResult result = new StreamResult(writer);
    TransformerFactory tf = TransformerFactory.newInstance();
    Transformer transformer = tf.newTransformer();
    transformer.transform(domSource, result);
    writer.flush();

    InputStream isNewXML = new ByteArrayInputStream(out.toByteArray());
}

From source file:cool.pandora.modeller.GetContainerTest.java

public static void main(final String[] args) throws IOException {
    try {/*from   www .  ja v a2  s  .  c  o m*/
        final String resource = ModellerClient.doGetContainerResources(
                URI.create("http://localhost:8080/fcrepo/rest/collection/test/001/res"));
        final Model model = ModelFactory.createDefaultModel();
        model.read(new ByteArrayInputStream(resource.getBytes()), null, "TTL");
        final ArrayList<String> children = getChilden(model);
        model.write(System.out, "TTL");
        System.out.println(children);
    } catch (ModellerClientFailedException e) {
        System.out.println(getMessage(e));
    }
}

From source file:net.itransformers.bgpPeeringMap.ThirdTransformation.java

public static void main(String[] args) throws Exception {

    ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream();

    XsltTransformer transformer = new XsltTransformer();
    File xsltFileName1 = new File("/Users/niau/trunk/bgpPeeringMap/conf/xslt/reorder.xslt");

    byte[] rawData = readRawDataFile(
            "/Users/niau/trunk/bgpPeeringMap/src/main/resources/bgpPeeringMap.graphml");
    ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData);
    transformer.transformXML(inputStream1, xsltFileName1, outputStream1);
    File outputFile1 = new File("/Users/niau/trunk/bgpPeeringMap/src/main/resources",
            "bgpPeeringMap2.graphxml");

    FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray()));

}

From source file:net.sf.jabb.util.text.test.KeywordMatcherExample.java

/**
 * @param args//ww w.  j  a v a  2s. c  om
 * @throws IOException 
 * @throws ClassNotFoundException 
 */
public static void main(String[] args) throws IOException, ClassNotFoundException {
    System.out.println("====  ====");
    KeywordMatcher m = showExample(null);

    System.out.println("==== ? ====");
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(baos);
    oos.writeObject(m);
    byte[] binary = baos.toByteArray();
    ByteArrayInputStream bais = new ByteArrayInputStream(binary);
    ObjectInputStream ois = new ObjectInputStream(bais);
    KeywordMatcher m2 = (KeywordMatcher) ois.readObject();
    showExample(m2);

    System.out.println("==== ? ====");
    KeywordMatcher m3 = new KeywordMatcher(m);
    showExample(m3);

}

From source file:com.taveloper.http.test.JsonParserDataBindTest.java

/**
 * @param args the command line arguments
 *//*from  w w  w . j a  v a 2s  .  c o  m*/
public static void main(String[] args) throws UnsupportedEncodingException, IOException {
    //        ByteArrayInputStream bais1 = new ByteArrayInputStream(json.getBytes("UTF-8"));
    JacksonFactory factory = new JacksonFactory();
    //        ActivityFeed parseAuto = parseAuto(factory, bais1);
    for (int i = 0; i < 10000; i++) {
        ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes("UTF-8"));
        ActivityFeed parseManual = parseAuto(factory, bais);
        //            if (!parseManual.equals(parseAuto)) {
        //                System.out.println("No activities found.");
        //            }
        System.out.println(i);
    }
}