本文整理汇总了Java中org.apache.commons.io.output.WriterOutputStream类的典型用法代码示例。如果您正苦于以下问题:Java WriterOutputStream类的具体用法?Java WriterOutputStream怎么用?Java WriterOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
WriterOutputStream类属于org.apache.commons.io.output包,在下文中一共展示了WriterOutputStream类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPublicKeys
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
private static List<String> getPublicKeys() throws Exception {
return new JschConfigSessionFactory() {
@Override
protected void configure(OpenSshConfig.Host hc, Session session) {
}
List<String> getPublicKeys() throws Exception {
JSch jSch = createDefaultJSch(FS.DETECTED);
List<String> keys = new ArrayList<>();
for (Object o : jSch.getIdentityRepository().getIdentities()) {
Identity i = (Identity) o;
KeyPair keyPair = KeyPair.load(jSch, i.getName(), null);
StringBuilder sb = new StringBuilder();
try (StringBuilderWriter sbw = new StringBuilderWriter(sb);
OutputStream os = new WriterOutputStream(sbw, "UTF-8")) {
keyPair.writePublicKey(os, keyPair.getPublicKeyComment());
} finally {
keyPair.dispose();
}
keys.add(sb.toString().trim());
}
return keys;
}
}.getPublicKeys();
}
示例2: assertOutputConversion_viaCharsetName
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
private void assertOutputConversion_viaCharsetName(String charsetName, boolean conversionErrorsExpected)
throws Exception {
byte[] originalBytes = createBytes();
{
// byte array as byte stream
ByteArrayOutputStream targetByteStream = new ByteArrayOutputStream();
// byte stream as character stream
Writer targetWriter = new OutputStreamWriter(targetByteStream, charsetName);
// modifying writer (we don't modify here)
Writer modifyingWriter = new ModifyingWriter(targetWriter, new RegexModifier("a", 0, "a"));
// character stream as byte stream
OutputStream modifyingByteStream = new WriterOutputStream(modifyingWriter, charsetName);
// byte stream as byte array
IOUtils.write(originalBytes, modifyingByteStream);
modifyingByteStream.close();
assertBytes(originalBytes, targetByteStream.toByteArray(), conversionErrorsExpected);
}
}
示例3: commandFailed
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
@Override
public <C extends ICommand> void commandFailed(Class<C> command, Throwable cause) {
try {
StringWriter writer = new StringWriter();
writer.write("Command " + command.getName() + " failed");
if (cause.getMessage() != null) {
writer.write(" with message " + cause.getMessage() + "\n");
} else {
writer.write("\n");
}
writer.write("Time stamp: " + DateTime.now() + "\n");
writer.write("Stacktrace: ");
cause.printStackTrace(new PrintStream(new WriterOutputStream(writer)));
fMailService.sendASAP(fDestinationEmailAddress, fSourceEmailAddress, writer.toString(), SCHEDULED_ERROR_SUBJECT);
} catch (EmailException exception) {
// The system failed at failing (looks like Windows)
LOGGER.error("Error while reporting error for cron", exception);
}
}
示例4: toString
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
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();
}
示例5: launch
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
@Override public void launch() throws IOException, InterruptedException {
if (launchCommand == null) {
commandField.setText("This launcher does not support launch in test mode.");
showAndWait();
return;
}
launchCommand.copyOutputTo(new WriterOutputStream(new TextAreaWriter(outputArea), Charset.defaultCharset()));
launchCommand.setMessageArea(new WriterOutputStream(new TextAreaWriter(errorArea), Charset.defaultCharset()));
if (launchCommand.start() == ITestLauncher.OK_OPTION) {
commandField.setText(launchCommand.toString());
showAndWait();
}
}
示例6: test
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
@Test
public void test() throws Exception {
String config;
try(StringWriter sw = new StringWriter();
OutputStream osw = new WriterOutputStream(sw, StandardCharsets.UTF_8)) {
service.write(MimeTypeUtils.APPLICATION_JSON_VALUE, osw);
config = sw.toString();
}
System.out.println(config);
try (StringReader sr = new StringReader(config);
InputStream is = new ReaderInputStream(sr, StandardCharsets.UTF_8)) {
service.read(MimeTypeUtils.APPLICATION_JSON_VALUE, is);
}
sampleBean.check();
}
示例7: decode
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
/**
* Dekodiert einen UTF-8-QUOTED-PRINTABLE-String in einen Java-Unicode-String.
*/
public String decode(String in) {
try {
InputStream input = MimeUtility.decode(new ReaderInputStream(new StringReader(in), "UTF-8"),
"quoted-printable");
StringWriter sw = new StringWriter();
OutputStream output = new WriterOutputStream(sw, "UTF-8");
copyAndClose(input, output);
return sw.toString();
} catch (Exception e) {
throw new RuntimeException("Exception caught in VntConverter.encode(in):", e);
}
}
示例8: encode
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
/**
* Enkodiert einen Java-Unicode-String in einen UTF-8-QUOTED-PRINTABLE-String.
*/
public String encode(String in) {
try {
InputStream input = new ReaderInputStream(new StringReader(in), "UTF-8");
StringWriter sw = new StringWriter();
OutputStream output = MimeUtility.encode(new WriterOutputStream(sw), "quoted-printable");
copyAndClose(input, output);
return sw.toString().replaceAll("=\\x0D\\x0A", "").replaceAll("\\x0D\\x0A", "=0D=0A");
} catch (Exception e) {
throw new RuntimeException("Exception caught in VntConverter.encode(in):", e);
}
}
示例9: executeCommand
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
private Future<CommandResult> executeCommand(String command, File executionDirectory, boolean silent)
throws IOException {
StringWriter writer = new StringWriter();
DefaultExecuteResultHandler resultHandler = new DefaultExecuteResultHandler();
try (WriterOutputStream outputStream = new WriterOutputStream(writer)) {
String outerCommand = "/bin/bash -lc";
CommandLine outer = CommandLine.parse(outerCommand);
outer.addArgument(command, false);
DefaultExecutor executor = new DefaultExecutor();
executor.setWorkingDirectory(executionDirectory);
executor.setStreamHandler(new PumpStreamHandler(silent ? outputStream : System.out, null));
executor.execute(outer, ENVIRONMENT, resultHandler);
resultHandler.waitFor();
} catch (InterruptedException e) {
throw new IllegalStateException(e);
}
return new AsyncResult<CommandResult>(
new CommandResult(resultHandler.getExitValue(), writer.toString(), resultHandler.getException()));
}
示例10: assertOutputConversion_viaCharsetEncoder
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
private void assertOutputConversion_viaCharsetEncoder(String charsetName, boolean conversionErrorsExpected)
throws Exception {
// find charset
Charset charset = Charset.forName(charsetName);
// // configure decoder
// CharsetDecoder decoder = charset.newDecoder();
// decoder.onUnmappableCharacter(CodingErrorAction.REPORT);
// configure encoder
CharsetEncoder encoder = charset.newEncoder();
encoder.onUnmappableCharacter(CodingErrorAction.REPORT);
byte[] originalBytes = createBytes();
boolean conversionErrorsFound;
try {
// byte array as byte stream
ByteArrayOutputStream targetByteStream = new ByteArrayOutputStream();
// byte stream as character stream
Writer targetWriter = new OutputStreamWriter(targetByteStream, encoder);
// modifying writer (we don't modify here)
Writer modifyingWriter = new ModifyingWriter(targetWriter, new RegexModifier("a", 0, "a"));
// character stream as byte stream
OutputStream modifyingByteStream = new WriterOutputStream(modifyingWriter, charset); // encoder
// not
// supported
// here!!!
// byte stream as byte array
IOUtils.write(originalBytes, modifyingByteStream);
modifyingByteStream.close();
assertBytes(originalBytes, targetByteStream.toByteArray(), conversionErrorsExpected);
conversionErrorsFound = false;
} catch (MalformedInputException e) {
conversionErrorsFound = true;
}
assertEquals(conversionErrorsExpected, conversionErrorsFound);
}
示例11: doSave
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
@Override
protected void doSave(XMISerializer serializer, CDOTransaction trans, String realCdoRepositoryPath)
throws IOException {
CDOTextResource textRes = trans.getOrCreateTextResource(realCdoRepositoryPath);
textRes.setEncoding(DEFAULT_CHARSET_NAME);
StringWriter writer = new StringWriter();
try (WriterOutputStream wos = new WriterOutputStream(writer, DEFAULT_CHARSET)) {
serializer.serialize(wos);
try (StringReader reader = new StringReader(writer.getBuffer().toString())) {
CDOClob clob = new CDOClob(reader);
textRes.setContents(clob);
}
}
}
示例12: writeValue
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
/**
* Writes out a given name / value pair.
* This is similar to {@link XMLWriter#writeVal(String, Object)}.
* This is needed because that similar method is not extensible and cannot be overriden
* (it is called recursively by other methods).
*
* @param name the name of the attribute.
* @param value the value of the attribute.
* @param data the complete set of response values.
* @throws IOException in case of I/O failure.
*/
public void writeValue(final String name, final Object value, final NamedList<?> data) throws IOException {
if (value == null) {
writeNull(name);
} else if (value instanceof ResultSet) {
final int start = req.getParams().getInt(CommonParams.START, 0);
final int rows = req.getParams().getInt(CommonParams.ROWS, 10);
writeStartDocumentList("response", start, rows, (Integer) data.remove(Names.NUM_FOUND), 1.0f);
final XMLOutput outputter = new XMLOutput(false);
outputter.format(new WriterOutputStream(writer), (ResultSet)value);
writeEndDocumentList();
} else if (value instanceof String || value instanceof Query) {
writeStr(name, value.toString(), false);
} else if (value instanceof Number) {
if (value instanceof Integer || value instanceof Short || value instanceof Byte) {
writeInt(name, value.toString());
} else if (value instanceof Long) {
writeLong(name, value.toString());
} else if (value instanceof Float) {
writeFloat(name, ((Float) value).floatValue());
} else if (value instanceof Double) {
writeDouble(name, ((Double) value).doubleValue());
}
} else if (value instanceof Boolean) {
writeBool(name, value.toString());
} else if (value instanceof Date) {
writeDate(name, (Date) value);
} else if (value instanceof Map) {
writeMap(name, (Map<?,?>) value, false, true);
} else if (value instanceof NamedList) {
writeNamedList(name, (NamedList<?>) value);
} else if (value instanceof Iterable) {
writeArray(name, ((Iterable<?>) value).iterator());
} else if (value instanceof Object[]) {
writeArray(name, (Object[]) value);
} else if (value instanceof Iterator) {
writeArray(name, (Iterator<?>) value);
}
}
示例13: setupLogging
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
public static void setupLogging(Session session, Log log, ParameterInclude params) throws AxisFault {
// Note that debugging might already be enabled by the mail.debug property and we should
// take care to override it.
if (log.isTraceEnabled()) {
// This is the old behavior: just set debug to true
session.setDebug(true);
}
if (ParamUtils.getOptionalParamBoolean(params, MailConstants.TRANSPORT_MAIL_DEBUG, false)) {
// Redirect debug output to where it belongs, namely to the logs!
session.setDebugOut(new PrintStream(new WriterOutputStream(new LogWriter(log)), true));
// Only enable debug afterwards since the call to setDebug might already cause debug output
session.setDebug(true);
}
}
示例14: beforeClass
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
@BeforeClass
public static void beforeClass() {
realSystemOut = System.out;
WriterOutputStream wout = new WriterOutputStream(out);
PrintStream pw = new PrintStream(wout);
System.setOut(pw);
}
示例15: writeJson
import org.apache.commons.io.output.WriterOutputStream; //导入依赖的package包/类
/**
* Output the data of the table as a JSON
*
* @param table
* the {@link ConsoleTable} to output
*
* @param writer
* the {@link PrintWriter} to write to
*/
public void writeJson(ConsoleTable table, PrintWriter writer) {
OutputStream os = new WriterOutputStream(writer);
PrintStream ps = new PrintStream(os);
try {
writeJson(table, ps);
} finally {
ps.close();
}
}