List of usage examples for java.io ByteArrayOutputStream reset
public synchronized void reset()
From source file:org.jactr.tools.async.message.ast.BaseASTMessage.java
private void writeObject(java.io.ObjectOutputStream out) throws IOException { out.defaultWriteObject();//from ww w . ja v a2s. c o m if (_ast != null) { out.writeBoolean(true); out.writeBoolean(_compress); if (_compress) { /* * go to a GZIPOutputStream */ ByteArrayOutputStream baos = _localBAOS.get(); if (baos == null) { baos = new ByteArrayOutputStream(); _localBAOS.set(baos); } baos.reset(); DataOutputStream zip = new DataOutputStream(new GZIPOutputStream(baos)); Serializer.write(_ast, zip); zip.flush(); zip.close(); // byte[] bytes = baos.toByteArray(); if (LOGGER.isDebugEnabled()) LOGGER.debug(String.format("Writing %d compressed bytes", baos.size())); out.writeInt(baos.size()); baos.writeTo(out); // if (LOGGER.isDebugEnabled()) // LOGGER.debug("Compressed AST to "+bytes.length); // out.writeInt(bytes.length); // out.write(bytes); } else Serializer.write(_ast, out); } else out.writeBoolean(false); }
From source file:gov.nih.nci.cacis.transform.XMLToRdfTransformerTest.java
@Test public void transformStream() throws XMLStreamException, TransformerException, URISyntaxException, IOException { final ByteArrayOutputStream os = new ByteArrayOutputStream(); final Map<String, String> params = new HashMap<String, String>(); params.put("BaseURI", "http://yadda.com/someUUID"); transform.transform(params, sampleMessageIS, os); assertNotNull(os);//from w w w . ja va2 s. c o m assertTrue(os.size() > 0); os.reset(); transform.transform(params, sampleTrimIS, os); assertNotNull(os); assertTrue(os.size() > 0); }
From source file:org.chimi.s4s.config.Log4jConfiguratorTest.java
@Test public void configure() { ByteArrayOutputStream baout = new ByteArrayOutputStream(200); PrintStream out = new PrintStream(baout); System.setOut(out);/*from ww w . j av a2 s. co m*/ System.setProperty(Log4jConfigurator.CONFIG_PATH_SYSTEM_PROPERTY, "src/test/resources/org/chimi/s4s/config/test-log4j.properties"); Log4jConfigurator.configure(); baout.reset(); // SLF4J Logger logger = LoggerFactory.getLogger(getClass()); logger.info(""); assertEquals("INFO - ", new String(baout.toByteArray()).trim()); baout.reset(); // JCL Log log = LogFactory.getLog(getClass()); log.warn(""); assertEquals("WARN - ", new String(baout.toByteArray()).trim()); }
From source file:com.linuxbox.enkive.importer.AbstractMessageImporter.java
protected void sendMessage(Message m) throws IOException, MessagingException { ByteArrayOutputStream os = new ByteArrayOutputStream(); m.writeTo(os);// w w w. java2s . com os.close(); BufferedReader reader = new BufferedReader( new InputStreamReader(new ByteArrayInputStream(os.toByteArray()))); sendMessage(reader); reader.close(); os.reset(); }
From source file:com.thoughtworks.go.server.websocket.ConsoleLogSender.java
private void flushBuffer(ByteArrayOutputStream buffer, SocketEndpoint webSocket) throws IOException { if (buffer.size() == 0) return;//w w w .j a v a 2s . c o m webSocket.send(ByteBuffer.wrap(maybeGzipIfLargeEnough(buffer.toByteArray()))); buffer.reset(); }
From source file:org.pentaho.di.job.entries.zipfile.JobEntryZipFileIT.java
@Test public void processFile_ReturnsTrue_OnSuccess() throws Exception { final String zipPath = "ram://pdi-15013.zip"; final String content = "temp file"; final File tempFile = createTempFile(content); tempFile.deleteOnExit();//w w w . jav a2 s. c om try { Result result = new Result(); JobEntryZipFile entry = new JobEntryZipFile(); assertTrue(entry.processRowFile(new Job(), result, zipPath, null, null, tempFile.getAbsolutePath(), null, false)); } finally { tempFile.delete(); } FileObject zip = KettleVFS.getFileObject(zipPath); assertTrue("Zip archive should be created", zip.exists()); ByteArrayOutputStream os = new ByteArrayOutputStream(); IOUtils.copy(zip.getContent().getInputStream(), os); ZipInputStream zis = new ZipInputStream(new ByteArrayInputStream(os.toByteArray())); ZipEntry entry = zis.getNextEntry(); assertEquals("Input file should be put into the archive", tempFile.getName(), entry.getName()); os.reset(); IOUtils.copy(zis, os); assertEquals("File's content should be equal to original", content, new String(os.toByteArray())); }
From source file:com.juick.android.JettyWsClient.java
public void readLoop() { try {//from w w w. ja v a2 s . c o m int b; //StringBuilder buf = new StringBuilder(); ByteArrayBuffer buf = new ByteArrayBuffer(16); boolean flagInside = false; StringBuilder baad = new StringBuilder(); int lenToRead = -1; ByteArrayOutputStream baos = new ByteArrayOutputStream(); while ((b = is.read()) != -1) { if (b == 0x81) { // 80 = final frame // 1 = text if ((b = is.read()) != -1) { lenToRead = b; baos.reset(); continue; } else { break; } } if (lenToRead != -1) { baos.write(b); lenToRead--; if (lenToRead == 0) { lenToRead = -1; if (listener != null) { listener.onWebSocketTextFrame(new String(baos.toByteArray(), "utf-8")); } } } } System.err.println("DISCONNECTED readLoop"); disconnect(); } catch (Exception e) { System.err.println(e); } }
From source file:org.apache.hadoop.hbase.TestGet.java
/** * the test/*from w w w . j a va 2s .c om*/ * @throws IOException */ public void testGet() throws IOException { MiniDFSCluster cluster = null; try { // Initialization cluster = new MiniDFSCluster(conf, 2, true, (String[]) null); FileSystem fs = cluster.getFileSystem(); Path dir = new Path("/hbase"); fs.mkdirs(dir); HTableDescriptor desc = new HTableDescriptor("test"); desc.addFamily(new HColumnDescriptor(CONTENTS.toString())); desc.addFamily(new HColumnDescriptor(HConstants.COLUMN_FAMILY.toString())); HRegionInfo info = new HRegionInfo(0L, desc, null, null); Path regionDir = HRegion.getRegionDir(dir, info.regionName); fs.mkdirs(regionDir); HLog log = new HLog(fs, new Path(regionDir, "log"), conf); HRegion r = new HRegion(dir, log, fs, conf, info, null); // Write information to the table long lockid = r.startUpdate(ROW_KEY); ByteArrayOutputStream bytes = new ByteArrayOutputStream(); DataOutputStream s = new DataOutputStream(bytes); CONTENTS.write(s); r.put(lockid, CONTENTS, bytes.toByteArray()); bytes.reset(); HGlobals.rootRegionInfo.write(s); r.put(lockid, HConstants.COL_REGIONINFO, Writables.getBytes(HGlobals.rootRegionInfo)); r.commit(lockid, System.currentTimeMillis()); lockid = r.startUpdate(ROW_KEY); r.put(lockid, HConstants.COL_SERVER, Writables.stringToBytes(new HServerAddress(SERVER_ADDRESS).toString())); r.put(lockid, HConstants.COL_STARTCODE, Writables.longToBytes(lockid)); r.put(lockid, new Text(HConstants.COLUMN_FAMILY + "region"), "region".getBytes(HConstants.UTF8_ENCODING)); r.commit(lockid, System.currentTimeMillis()); // Verify that get works the same from memcache as when reading from disk // NOTE dumpRegion won't work here because it only reads from disk. verifyGet(r, SERVER_ADDRESS); // Close and re-open region, forcing updates to disk r.close(); log.rollWriter(); r = new HRegion(dir, log, fs, conf, info, null); // Read it back verifyGet(r, SERVER_ADDRESS); // Update one family member and add a new one lockid = r.startUpdate(ROW_KEY); r.put(lockid, new Text(HConstants.COLUMN_FAMILY + "region"), "region2".getBytes(HConstants.UTF8_ENCODING)); String otherServerName = "bar.foo.com:4321"; r.put(lockid, HConstants.COL_SERVER, Writables.stringToBytes(new HServerAddress(otherServerName).toString())); r.put(lockid, new Text(HConstants.COLUMN_FAMILY + "junk"), "junk".getBytes(HConstants.UTF8_ENCODING)); r.commit(lockid, System.currentTimeMillis()); verifyGet(r, otherServerName); // Close region and re-open it r.close(); log.rollWriter(); r = new HRegion(dir, log, fs, conf, info, null); // Read it back verifyGet(r, otherServerName); // Close region once and for all r.close(); log.closeAndDelete(); } finally { if (cluster != null) { cluster.shutdown(); } } }
From source file:org.jboss.as.test.integration.management.cli.CliVariablesTestCase.java
/** * Tests the 'unset' command/*from w ww .j av a 2 s. co m*/ * @throws Exception */ @Test public void testSetAndUnsetVariables() throws Exception { final String VAR1_NAME = "variable_1"; final String VAR1_VALUE = "value_1"; final ByteArrayOutputStream cliOut = new ByteArrayOutputStream(); final CommandContext ctx = CLITestUtil.getCommandContext(cliOut); ctx.handle("set " + VAR1_NAME + "=" + VAR1_VALUE); cliOut.reset(); ctx.handle("echo $" + VAR1_NAME); assertTrue(cliOut.toString().contains(VAR1_VALUE)); ctx.handle("unset " + VAR1_NAME); try { ctx.handle("$" + VAR1_NAME); fail(VAR1_NAME + " should be unset"); } catch (UnresolvedVariableException ex) { //expected } cliOut.reset(); ctx.handle("set"); assertFalse(cliOut.toString().contains(VAR1_NAME)); assertTrue(ctx.getExitCode() == 0); }
From source file:svn.CopyrightTest.java
public void testCopyright() throws Exception { List<File> sourceFiles = new ArrayList<File>(); list(new File("src"), sourceFiles); list(new File("test"), sourceFiles); ByteArrayOutputStream fdata = new ByteArrayOutputStream(); for (File f : sourceFiles) { if (f.getPath().replace('\\', '/').startsWith("src/gen/")) { // skip jaxb generated files continue; }//w ww . j ava2s.c om FileUtils.copyFile(f, fdata); String data = fdata.toString("ISO-8859-1"); checkNote(f, data); fdata.reset(); } }