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()); }
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()); }
@Test public void testWriteImmediately() throws IOException { final StringWriter writer = new StringWriter(); final WriterOutputStream out = new WriterOutputStream(writer, "us-ascii", 1024, true); out.write("abc".getBytes("us-ascii")); assertEquals("abc", writer.toString()); out.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(); }
@Override protected StreamRDF getStream(Writer writer, Configuration config) { return new StreamRDF2Thrift(new WriterOutputStream(writer, Charset.forName("utf-8")), false); }
@Override protected StreamRDF getStream(Writer writer, Configuration config) { return new StreamRDF2Thrift(new WriterOutputStream(writer, Charset.forName("utf-8")), false); }
public DigestWriter(Writer delegateWriter, MessageDigest digest) { this.digestWriter = new OutputStreamWriter(new DigestOutputStream( new WriterOutputStream(delegateWriter), digest), Charsets.UTF_8); }
@Override protected void init() throws IOException { super.init(); this.commandFactory = new CommandFactoryWithIO(this.commandFactory, new PrintStream(new WriterOutputStream(out)), System.err); }
/** * Creates a new {@link PropertiesTextWriter} that will write to the supplied * {@link Writer}. * * @param writer * The {@link Writer} to write the {@link Properties} document * to. */ public PropertiesTextWriter(final Writer writer) { this.os = new WriterOutputStream(writer, PropertiesFormat.TEXT.getCharset()); }
/** * Creates a new {@link PropertiesXMLWriter} that will write to the supplied * {@link Writer}. * * @param writer * The {@link Writer} to write the {@link Properties} document * to. */ public PropertiesXMLWriter(final Writer writer) { this.os = new WriterOutputStream(writer, PropertiesFormat.XML.getCharset()); }
@Override public <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config) { return new StreamRdfQuadWriter<TKey>(new StreamRDF2Thrift(new WriterOutputStream(writer, Charset.forName("utf-8")), false), writer); }
/** * Creates a new {@link PropertiesXMLWriter} that will write to the supplied * {@link Writer}. * * @param writer * The {@link Writer} to write the {@link Properties} document * to. */ public PropertiesXMLWriter(final Writer writer) { this.os = new WriterOutputStream(writer, PropertiesFormat.XML.getCharset()); }
/** * Creates a new {@link PropertiesTextWriter} that will write to the supplied * {@link Writer}. * * @param writer * The {@link Writer} to write the {@link Properties} document * to. */ public PropertiesTextWriter(final Writer writer) { this.os = new WriterOutputStream(writer, PropertiesFormat.TEXT.getCharset()); }
@Override public <TKey> RecordWriter<TKey, QuadWritable> createQuadWriter(Writer writer, Configuration config) { return new StreamRdfQuadWriter<TKey>(new StreamRDF2Thrift(new WriterOutputStream(writer, Charset.forName("utf-8")), false), writer); }
@Override public <TKey> RecordWriter<TKey, TripleWritable> createTripleWriter(Writer writer, Configuration config) { return new StreamRdfTripleWriter<TKey>(new StreamRDF2Thrift(new WriterOutputStream(writer, Charset.forName("utf-8")), false), writer); }
@Override public void writeTo(Writer writer, Syntax syntax) throws IOException, ModelRuntimeException, SyntaxNotSupportedException { WriterOutputStream stream = new WriterOutputStream(writer, StandardCharsets.UTF_8); writeTo(stream, syntax); }
default String asString() throws IOException { final StringWriter strData = new StringWriter(); try (final WriterOutputStream wos = new WriterOutputStream(strData, Charset.defaultCharset())) { writeTo(wos); } return strData.toString(); } }
public static void logDocument(Node doc, Logger logger) throws IOException, TransformerException { StringWriter stringWriter = new StringWriter(); WriterOutputStream os = new WriterOutputStream(stringWriter, Charset.forName("UTF-8")); printDocument(doc, os, true); os.close(); logger.debug(stringWriter.toString()); }
public static String writeToString(EObject instance, NonContainmentReferenceHandling refOption, HashMap<String, Object> saveOptions) throws IOException { StringWriter stringWriter = new StringWriter(); WriterOutputStream os = new WriterOutputStream(stringWriter, Charset.forName("UTF-8")); writeToStream(instance, os, refOption, saveOptions); os.close(); return stringWriter.toString(); }
public void encode(ContentHandler output) throws Exception { ((LexicalHandler) output).startCDATA(); try (OutputStream os = new WriterOutputStream(new ContentHandlerWriter(output))) { ppio.encode(object, os); } ((LexicalHandler) output).endCDATA(); }