List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:House.java
public static void main(String[] args) throws IOException, ClassNotFoundException { House house = new House(); List animals = new ArrayList(); animals.add(new Animal("Bosco the dog", house)); animals.add(new Animal("Ralph the hamster", house)); animals.add(new Animal("Fronk the cat", house)); System.out.println("animals: " + animals); ByteArrayOutputStream buf1 = new ByteArrayOutputStream(); ObjectOutputStream o1 = new ObjectOutputStream(buf1); o1.writeObject(animals);// www .j a va 2 s . com o1.writeObject(animals); // Write a 2nd set // Write to a different stream: ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); ObjectOutputStream o2 = new ObjectOutputStream(buf2); o2.writeObject(animals); // Now get them back: ObjectInputStream in1 = new ObjectInputStream(new ByteArrayInputStream(buf1.toByteArray())); ObjectInputStream in2 = new ObjectInputStream(new ByteArrayInputStream(buf2.toByteArray())); List animals1 = (List) in1.readObject(), animals2 = (List) in1.readObject(), animals3 = (List) in2.readObject(); System.out.println("animals1: " + animals1); System.out.println("animals2: " + animals2); System.out.println("animals3: " + animals3); }
From source file:net.itransformers.bgpPeeringMap.DavidPiegzaFormatTransformer.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/david_piegza.xslt"); byte[] rawData = readRawDataFile("/Users/niau/test1/network/version1/undirected/imap.graphml"); ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData); transformer.transformXML(inputStream1, xsltFileName1, outputStream1, null, null); File outputFile1 = new File("/Users/niau/trunk/bgpPeeringMap/src/main/resources", "imap.xml"); FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray())); }
From source file:com.taveloper.http.test.JsonParserManualTest.java
/** * @param args the command line arguments *//*from ww w .j a va2 s . c om*/ public static void main(String[] args) throws UnsupportedEncodingException, IOException { // ByteArrayInputStream bais1 = new ByteArrayInputStream(json.getBytes("UTF-8")); // ActivityFeed parseAuto = parseAuto(bais1); com.fasterxml.jackson.core.JsonFactory factory = new com.fasterxml.jackson.core.JsonFactory(); for (int i = 0; i < 1; i++) { ByteArrayInputStream bais = new ByteArrayInputStream(json.getBytes("UTF-8")); ActivityFeed parseManual = parseManual(factory, bais); // if (!parseManual.equals(parseAuto)) { // System.out.println("No activities found."); // } System.out.println(i); if (parseManual.getActivities().isEmpty()) { System.out.println("No activities found."); } else { for (Activity activity : parseManual.getActivities()) { System.out.println(); System.out.println("-----------------------------------------------"); System.out.println("HTML Content: " + activity.getActivityObject().getContent()); System.out.println("+1's: " + activity.getActivityObject().getPlusOners().getTotalItems()); System.out.println("URL: " + activity.getUrl()); System.out.println("ID: " + activity.get("id")); } } } // ByteArrayInputStream bais2 = new ByteArrayInputStream(json.getBytes("UTF-8")); // if (parseManual1.equals(parseAuto(bais2))) { // System.out.println("Yeah!!"); // } }
From source file:com.clouddrive.parth.AmazonOperations.java
public static void main(String[] args) { InputStream is = new ByteArrayInputStream( ByteToArray.getByteFromFile(new File("C:\\Users\\Administrator\\Desktop\\Temp.txt"))); AmazonOperations a = new AmazonOperations(); System.out.println(a.isBucketPresent("samta123")); // a.s3.createBucket("samta123"); a.uploadFile(is, "samta123", "samta123"); }
From source file:Main.java
public static void main(String args[]) throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); float sampleRate = 8000; int sampleSizeInBits = 8; int channels = 1; boolean signed = true; boolean bigEndian = true; final AudioFormat format = new AudioFormat(sampleRate, sampleSizeInBits, channels, signed, bigEndian); DataLine.Info info = new DataLine.Info(TargetDataLine.class, format); final TargetDataLine line = (TargetDataLine) AudioSystem.getLine(info); line.open(format);//from w ww . j av a 2s. com line.start(); Runnable runner = new Runnable() { int bufferSize = (int) format.getSampleRate() * format.getFrameSize(); byte buffer[] = new byte[bufferSize]; public void run() { try { int count = line.read(buffer, 0, buffer.length); if (count > 0) { out.write(buffer, 0, count); } out.close(); } catch (IOException e) { System.err.println("I/O problems: " + e); System.exit(-1); } } }; Thread captureThread = new Thread(runner); captureThread.start(); byte audio[] = out.toByteArray(); InputStream input = new ByteArrayInputStream(audio); final SourceDataLine line1 = (SourceDataLine) AudioSystem.getLine(info); final AudioInputStream ais = new AudioInputStream(input, format, audio.length / format.getFrameSize()); line1.open(format); line1.start(); runner = new Runnable() { int bufferSize = (int) format.getSampleRate() * format.getFrameSize(); byte buffer[] = new byte[bufferSize]; public void run() { try { int count; while ((count = ais.read(buffer, 0, buffer.length)) != -1) { if (count > 0) { line1.write(buffer, 0, count); } } line1.drain(); line1.close(); } catch (IOException e) { System.err.println("I/O problems: " + e); System.exit(-3); } } }; Thread playThread = new Thread(runner); playThread.start(); }
From source file:io.fluo.metrics.config.ReporterStarterImpl.java
public static void main(String[] args) { new ReporterStarterImpl().start(new Params() { @Override/*from w ww .ja v a 2 s. com*/ public MetricRegistry getMetricRegistry() { return new MetricRegistry(); } @Override public String getDomain() { return "test"; } @Override public Configuration getConfiguration() { FluoConfiguration conf = new FluoConfiguration(); conf.setMetricsYaml(new ByteArrayInputStream("---\nfrequency: 60 seconds\n".getBytes())); return conf; } }); }
From source file:com.betfair.testing.utils.cougar.assertions.AssertionUtils.java
public static void main(String[] args) throws ParserConfigurationException, IOException, SAXException { Document expected = new XMLHelpers().createAsDocument( DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream( ("<a><b><c>1</c><c>2</c><c>3</c></b><b><c>1</c><c>2</c><c>3</c></b></a>").getBytes()))); Document actual = new XMLHelpers().createAsDocument( DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream( ("<a><b><c>2</c><c>1</c><c>3</c></b><b><c>3</c><c>2</c><c>1</c></b></a>").getBytes()))); try {//from w ww. j a va 2s .c om multiAssertEquals(expected, actual); System.out.println("Failed: should have been different"); } catch (AssertionError e) { System.out.println("Passed: were different"); } try { multiAssertEquals(expected, actual, "/a/b"); System.out.println("Passed: weren't different"); } catch (AssertionError e) { System.out.println("Failed: shouldn't have been different"); } }
From source file:com.vethrfolnir.TestJsonAfterUnmarshal.java
public static void main(String[] args) throws Exception { ArrayList<TestThing> tsts = new ArrayList<>(); for (int i = 0; i < 21; i++) { final int nr = i; tsts.add(new TestThing() { {// w w w.j a v a 2 s .c o m id = 1028 * nr + 256; name = "Name-" + nr; } }); } ObjectMapper mp = new ObjectMapper(); mp.setVisibilityChecker(mp.getDeserializationConfig().getDefaultVisibilityChecker() .withCreatorVisibility(JsonAutoDetect.Visibility.NONE) .withFieldVisibility(JsonAutoDetect.Visibility.ANY) .withGetterVisibility(JsonAutoDetect.Visibility.NONE) .withIsGetterVisibility(JsonAutoDetect.Visibility.NONE) .withSetterVisibility(JsonAutoDetect.Visibility.NONE)); mp.configure(SerializationFeature.INDENT_OUTPUT, true); ByteArrayOutputStream br = new ByteArrayOutputStream(); mp.writeValue(System.err, tsts); mp.writeValue(br, tsts); ByteArrayInputStream in = new ByteArrayInputStream(br.toByteArray()); tsts = mp.readValue(in, new TypeReference<ArrayList<TestThing>>() { }); System.err.println(); System.out.println("Got: " + tsts); }
From source file:com.yxy.chukonu.java.aws.sdk.s3.kms.managed.cmk.testKMSkeyUploadObject.java
public static void main(String[] args) throws Exception { String bucketName = "***bucket name***"; String objectKey = "ExampleKMSEncryptedObject"; //The key in the specified bucket under which the object is stored. String kms_cmk_id = "***AWS KMS customer master key ID***"; KMSEncryptionMaterialsProvider materialProvider = new KMSEncryptionMaterialsProvider(kms_cmk_id); encryptionClient = new AmazonS3EncryptionClient(new ProfileCredentialsProvider(), materialProvider, new CryptoConfiguration()); // Upload object using the encryption client. byte[] plaintext = "Hello World, S3 Client-side Encryption Using Asymmetric Master Key!".getBytes(); System.out.println("plaintext's length: " + plaintext.length); encryptionClient.putObject(new PutObjectRequest(bucketName, objectKey, new ByteArrayInputStream(plaintext), new ObjectMetadata())); // Download the object. S3Object downloadedObject = encryptionClient.getObject(bucketName, objectKey); byte[] decrypted = IOUtils.toByteArray(downloadedObject.getObjectContent()); // Verify same data. Assert.assertTrue(Arrays.equals(plaintext, decrypted)); }
From source file:com.streamreduce.util.CAGenerator.java
public static void main(String[] args) throws Exception { KeyStore store = KeyStore.getInstance("JKS"); // store.load(CAGenerator.class.getResourceAsStream("/mmc-keystore.jks"), "ion-mmc".toCharArray()); store.load(null);//from w w w . j a v a 2 s . c o m KeyPair keypair = generateKeyPair(); X509Certificate cert = generateCACert(keypair); char[] password = "nodeable-agent".toCharArray(); store.setKeyEntry("nodeable", keypair.getPrivate(), password, new Certificate[] { cert }); store.store(new FileOutputStream("nodeable-keystore.jks"), password); byte[] certBytes = getCertificateAsBytes(cert); FileOutputStream output = new FileOutputStream("nodeable.crt"); IOUtils.copy(new ByteArrayInputStream(certBytes), output); output.close(); }