Refine search
private void testWithSingleByteWrite(final String testString, final String charsetName) throws IOException { final byte[] bytes = testString.getBytes(charsetName); final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, charsetName); for (final byte b : bytes) { out.write(b); } out.close(); assertEquals(testString, writer.toString()); }
/** * Close the stream. Any remaining content accumulated in the output buffer * will be written to the underlying {@link Writer}. After that * {@link Writer#close()} will be called. * @throws IOException if an I/O error occurs */ @Override public void close() throws IOException { processInput(true); flushOutput(); writer.close(); }
@Test public void testFlush() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, false); out.write("abc".getBytes("us-ascii")); assertEquals(0, writer.getBuffer().length()); out.flush(); assertEquals("abc", writer.toString()); out.close(); }
public static String toString(ExpressionNode node) { StringWriter writer = new StringWriter(); try (PrintStream os = new PrintStream(new WriterOutputStream(writer, StandardCharsets.UTF_8))) { print(node, os); } return writer.toString(); }
@Override protected void doStart() throws Exception { // global startup Orient.instance().startup(); // instance startup OServer server = new OServer(); server.setExtensionClassLoader(uberClassLoader); OServerConfiguration config = createConfiguration(); server.startup(config); // create default root user to avoid orientdb prompt on console server.addUser(OServerConfiguration.SRV_ROOT_ADMIN, null, "*"); // Log global configuration if (log.isDebugEnabled()) { StringWriter buff = new StringWriter(); // FIXME: Remove need for commons-io WriterOutputStream OGlobalConfiguration.dumpConfiguration(new PrintStream(new WriterOutputStream(buff), true)); log.debug("Global configuration:\n{}", buff); } server.activate(); log.info("Activated"); this.orientServer = server; }
@Override public OutputStream getOutputStream() { if (this.writerOutputStream == null) { this.writerOutputStream = new WriterOutputStream(this.printWriter, this.characterEncoding); } return writerOutputStream; }
file.getParentFile().mkdirs(); FileWriter fileWriter = new FileWriter(file, true); writerOutputStream = new WriterOutputStream(fileWriter, CHARSET_UTF8); if (writerOutputStream != null) { try { writerOutputStream.close();
/** * Write a single byte to the stream. * * @param b the byte to write * @throws IOException if an I/O error occurs */ @Override public void write(final int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
/** * Flush the stream. Any remaining content accumulated in the output buffer * will be written to the underlying {@link Writer}. After that * {@link Writer#flush()} will be called. * @throws IOException if an I/O error occurs */ @Override public void flush() throws IOException { flushOutput(); writer.flush(); }
default String asString() throws IOException { final StringWriter strData = new StringWriter(); try (final WriterOutputStream wos = new WriterOutputStream(strData, Charset.defaultCharset())) { writeTo(wos); } return strData.toString(); } }
@Override public OutputStream getOutputStream() { if (this.writerOutputStream == null) { this.writerOutputStream = new WriterOutputStream(this.printWriter, this.characterEncoding); } return writerOutputStream; }
/** * Write bytes from the specified byte array to the stream. * * @param b the byte array containing the bytes to write * @throws IOException if an I/O error occurs */ @Override public void write(final byte[] b) throws IOException { write(b, 0, b.length); }
/** * Decode the contents of the input ByteBuffer into a CharBuffer. * * @param endOfInput indicates end of input * @throws IOException if an I/O error occurs */ private void processInput(final boolean endOfInput) throws IOException { // Prepare decoderIn for reading decoderIn.flip(); CoderResult coderResult; while (true) { coderResult = decoder.decode(decoderIn, decoderOut, endOfInput); if (coderResult.isOverflow()) { flushOutput(); } else if (coderResult.isUnderflow()) { break; } else { // The decoder is configured to replace malformed input and unmappable characters, // so we should not get here. throw new IOException("Unexpected coder result"); } } // Discard the bytes that have been read decoderIn.compact(); }
default String asString() throws IOException { final StringWriter strData = new StringWriter(); try (final WriterOutputStream wos = new WriterOutputStream(strData, Charset.defaultCharset())) { writeTo(wos); } return strData.toString(); } }
private void testWithBufferedWrite(final String testString, final String charsetName) throws IOException { final byte[] expected = testString.getBytes(charsetName); final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, charsetName); int offset = 0; while (offset < expected.length) { final int length = Math.min(random.nextInt(128), expected.length-offset); out.write(expected, offset, length); offset += length; } out.close(); assertEquals(testString, writer.toString()); }
public OutputStream toStream(Writer output) { return new WriterOutputStream(output); }
/** * Write bytes from the specified byte array to the stream. * * @param b the byte array containing the bytes to write * @param off the start offset in the byte array * @param len the number of bytes to write * @throws IOException if an I/O error occurs */ @Override public void write(final byte[] b, int off, int len) throws IOException { while (len > 0) { final int c = Math.min(len, decoderIn.remaining()); decoderIn.put(b, off, c); processInput(false); len -= c; off += c; } if (writeImmediately) { flushOutput(); } }
/** * Write a single byte to the stream. * * @param b the byte to write * @throws IOException if an I/O error occurs */ @Override public void write(int b) throws IOException { write(new byte[] { (byte)b }, 0, 1); }
/** * Flush the stream. Any remaining content accumulated in the output buffer * will be written to the underlying {@link Writer}. After that * {@link Writer#flush()} will be called. * @throws IOException if an I/O error occurs */ @Override public void flush() throws IOException { flushOutput(); writer.flush(); }
static String dumpSegment(SegmentId id, int length, String segmentInfo, GCGeneration generation, SegmentReferences segmentReferences, RecordNumbers recordNumbers, Consumer<OutputStream> dumper) { StringWriter string = new StringWriter(); try (PrintWriter writer = new PrintWriter(string)) { writer.format("Segment %s (%d bytes)%n", id, length); if (segmentInfo != null) { writer.format("Info: %s, Generation: %s%n", segmentInfo, generation); } if (id != null && id.isDataSegmentId()) { writer.println("--------------------------------------------------------------------------"); int i = 1; for (SegmentId segmentId : segmentReferences) { writer.format("reference %02x: %s%n", i++, segmentId); } for (Entry entry : recordNumbers) { int offset = entry.getOffset(); writer.format("%10s record %08x: %08x @ %08x%n", entry.getType(), entry.getRecordNumber(), offset, getAddress(length, offset)); } } writer.println("--------------------------------------------------------------------------"); dumper.accept(new WriterOutputStream(writer, Charsets.UTF_8)); writer.println("--------------------------------------------------------------------------"); } return string.toString(); }