当前位置: 首页>>代码示例>>Java>>正文


Java WriterOutputStream类代码示例

本文整理汇总了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();
}
 
开发者ID:danielflower,项目名称:app-runner,代码行数:25,代码来源:SystemInfo.java

示例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);
    }
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:22,代码来源:ByteStreamTest.java

示例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);
	}
	

}
 
开发者ID:bioko,项目名称:system,代码行数:27,代码来源:CronFailureNotifier.java

示例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();
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:9,代码来源:ExpressionPrinter.java

示例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();
    }
}
 
开发者ID:jalian-systems,项目名称:marathonv5,代码行数:14,代码来源:TestApplication.java

示例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();
}
 
开发者ID:codeabovelab,项目名称:haven-platform,代码行数:16,代码来源:ReConfigurableBeanTest.java

示例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);
	}

}
 
开发者ID:udamken,项目名称:VntConverter,代码行数:17,代码来源:VntConverter.java

示例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);
	}
}
 
开发者ID:udamken,项目名称:VntConverter,代码行数:15,代码来源:VntConverter.java

示例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()));
}
 
开发者ID:spring-projects,项目名称:spring-data-dev-tools,代码行数:28,代码来源:CommonsExecOsCommandOperations.java

示例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);
}
 
开发者ID:rwitzel,项目名称:streamflyer,代码行数:41,代码来源:ByteStreamTest.java

示例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);
        }
    }
}
 
开发者ID:Cooperate-Project,项目名称:CooperateModelingEnvironment,代码行数:15,代码来源:TextbasedCDOResource.java

示例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);
	} 
}
 
开发者ID:spaziocodice,项目名称:SolRDF,代码行数:50,代码来源:HybridXMLWriter.java

示例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);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2-transports,代码行数:15,代码来源:MailUtils.java

示例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);
}
 
开发者ID:brain-bugs,项目名称:Klendathu,代码行数:8,代码来源:WriterTest.java

示例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();
	}
}
 
开发者ID:sangupta,项目名称:jerry-core,代码行数:19,代码来源:ConsoleTableWriter.java


注:本文中的org.apache.commons.io.output.WriterOutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。