本文整理汇总了Java中org.apache.commons.io.output.StringBuilderWriter类的典型用法代码示例。如果您正苦于以下问题:Java StringBuilderWriter类的具体用法?Java StringBuilderWriter怎么用?Java StringBuilderWriter使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
StringBuilderWriter类属于org.apache.commons.io.output包,在下文中一共展示了StringBuilderWriter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: offlineQuery
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
private static void offlineQuery(String sql) throws IOException {
StringBuilder output = new StringBuilder();
output.append("Query: ").append(sql).append("\n");
DBConnectionParameters params = new DBConnectionParameters();
try (Connection conn = DriverManager.getConnection(params.getConnectionURL(),
params.getLogin(), params.getPassword());
Statement statement = conn.createStatement()) {
try (ResultSet result = statement.executeQuery(sql)){
processResultSetForQuery(output, result);
}
} catch (Exception ex) {
try (PrintWriter pw = new PrintWriter(new StringBuilderWriter(output), true)) {
ex.printStackTrace(pw);
}
}
System.out.println(output.toString());
}
示例2: offlineExec
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
private static void offlineExec(String sql) throws IOException {
StringBuilder output = new StringBuilder();
output.append("Exec: ").append(sql).append("\n");
DBConnectionParameters params = new DBConnectionParameters();
try (Connection conn = DriverManager.getConnection(params.getConnectionURL(),
params.getLogin(), params.getPassword());
Statement statement = conn.createStatement()) {
boolean isResultSet = statement.execute(sql);
if (!isResultSet) {
output.append(statement.getUpdateCount()).append(" rows affected.\n");
}
} catch (Exception ex) {
try (PrintWriter pw = new PrintWriter(new StringBuilderWriter(output), true)) {
ex.printStackTrace(pw);
}
}
System.out.println(output.toString());
}
示例3: visitEnd
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
@Override
public void visitEnd() {
try {
accept(inner);
super.visitEnd();
} catch(Exception e){
Textifier t = new Textifier();
accept(new TraceMethodVisitor(t));
StringBuilderWriter sw = new StringBuilderWriter();
PrintWriter pw = new PrintWriter(sw);
t.print(pw);
pw.flush();
String bytecode = sw.getBuilder().toString();
logger.error(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e);
throw new RuntimeException(String.format("Failure while rendering method %s, %s, %s. ByteCode:\n %s", name, desc, signature, bytecode), e);
}
}
示例4: read
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
public static <T> Optional<T> read(Gson gson, File file, Type type) {
T ret = null;
if (file.isFile()) {
StringBuilder builder = new StringBuilder();
try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), "UTF-8"))) {
String line;
while ((line = reader.readLine()) != null)
builder.append(line).append('\n');
ret = read(gson, new StringReader(builder.toString()), type);
} catch (Exception e) {
Static.log("Error while read " + file.getName());
e.printStackTrace();
// Log file & Backup
builder.append('\n').append("=== 에러 로그 (수정&적용 시 이 부분을 지우세요) ===").append('\n');
e.printStackTrace(new PrintWriter(new StringBuilderWriter(builder)));
File backupFile = FileUtils.appendToName(file, "-" + System.currentTimeMillis(), ".broken");
FileUtils.write(backupFile, builder);
}
}
return Optional.ofNullable(ret);
}
示例5: domToString
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
public static String domToString(final Node doc,
final boolean pretty,
final boolean omitXml) {
try {
Transformer transformer = TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, omitXml ? "yes" : "no");
transformer.setOutputProperty(OutputKeys.METHOD, "xml");
transformer.setOutputProperty(OutputKeys.INDENT, pretty ? "yes" : "no");
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
if (pretty) {
transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
}
try (StringBuilderWriter writer = new StringBuilderWriter()) {
transformer.transform(new DOMSource(doc), new StreamResult(writer));
return writer.getBuilder().toString();
}
} catch (TransformerException e) {
throw new RuntimeException(e);
}
}
示例6: toString
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
/**
* 에러 메세지 상세화
*
* @param title
* 메세지 타이틀
* @param e
* @return
*/
public static String toString(String title, Throwable e) {
if (e == null)
return "[warnning] Exception is null";
String errMsg = "";
try (StringBuilderWriter sbw = new StringBuilderWriter()) {
try (PrintWriter printWriter = new PrintWriter(sbw, true)) {
if (title != null)
printWriter.write("############# ".concat(title).concat(" ##############\n"));
e.printStackTrace(printWriter);
}
errMsg = sbw.toString();
}
return errMsg;
}
示例7: deploy
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
@POST /* Maybe should be PUT, but too many hooks only use POST */
@Produces({MediaType.TEXT_PLAIN, MediaType.APPLICATION_JSON})
@Path("/{name}/deploy")
@ApiOperation(value = "Deploys an app", notes = "Deploys the app by fetching the latest changes from git, building it, " +
"starting it, polling for successful startup by making GET requests to /{name}/, and if it returns any HTTP response " +
"it shuts down the old version of the app. If any steps before that fail, the old version of the app will continue serving " +
"requests.")
@ApiResponses(value = {@ApiResponse(code = 200, message = "Returns 200 if the command was received successfully. Whether the build " +
"actually succeeds or fails is ignored. Returns streamed plain text of the build log and console startup, unless the Accept" +
" header includes 'application/json'.")})
public Response deploy(@Context UriInfo uriInfo, @ApiParam(example = "application/json") @HeaderParam("Accept") String accept,
@ApiParam(required = true, example = "app-runner-home") @PathParam("name") String name) throws IOException {
StreamingOutput stream = new UpdateStreamer(name);
if (MediaType.APPLICATION_JSON.equals(accept)) {
StringBuilderWriter output = new StringBuilderWriter();
try (WriterOutputStream writer = new WriterOutputStream(output)) {
stream.write(writer);
return app(uriInfo, name);
}
} else {
return Response.ok(stream).build();
}
}
示例8: getPublicKeys
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的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();
}
示例9: startAndStop
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
static void startAndStop(int attempt, String appName, AppRunner runner, int port, StringBuilderWriter buildLog, StringBuilderWriter consoleLog, Matcher<String> getResponseMatcher, Matcher<String> buildLogMatcher) throws Exception {
try {
try (Waiter startupWaiter = Waiter.waitForApp(appName, port)) {
runner.start(
new OutputToWriterBridge(buildLog),
new OutputToWriterBridge(consoleLog),
TestConfig.testEnvVars(port, appName),
startupWaiter);
}
try {
ContentResponse resp = httpClient.GET("http://localhost:" + port + "/" + appName + "/");
assertThat(resp.getStatus(), is(200));
assertThat(resp.getContentAsString(), getResponseMatcher);
assertThat(buildLog.toString(), buildLogMatcher);
} finally {
runner.shutdown();
}
} catch (Exception e) {
clearlyShowError(attempt, e, buildLog, consoleLog);
}
}
示例10: loadData
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
private String loadData(String name)
{
String data = null;
InputStream reader = getClass().getClassLoader().getResourceAsStream(name);
StringBuilder output = new StringBuilder();
StringBuilderWriter writer = new StringBuilderWriter(output);
try
{
IOUtils.copy(reader, writer);
}
catch (IOException ioe)
{
LOGGER.error("While loading test data", ioe);
}
data = writer.toString();
return data;
}
示例11: convertDataToCsv
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
private String convertDataToCsv(final RequestResultDTO requestResult, boolean withHeader) {
LOG.debug("convertDataToCsv - called for {}, withHeader={}", requestResult, withHeader);
final StringBuilder sb = new StringBuilder();
try (
final Writer writer = new StringBuilderWriter(sb);
final CSVWriter csvWriter = new CSVWriter(writer)) {
// header
if (withHeader) {
csvWriter.writeNext(requestResult.getHeaderLine().toArray(new String[0]));
}
// body
for (final List<String> line : requestResult.getResultLines()) {
csvWriter.writeNext(line.toArray(new String[0]));
}
} catch (final IOException e) {
LOG.error("Close failed on resource - expect leaks and incorrect operation", e);
}
return sb.toString();
}
示例12: errorMessage
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
private String errorMessage(String header, Exception e) {
StringBuilder res =
new StringBuilder()
.append(header)
.append("\nFull test case (in file ")
.append(p.getSourceFile())
.append("):\n")
.append(p.getNode().toJson(jwsettings));
if (e != null) {
res.append("\nFull error: ");
e.printStackTrace(new PrintWriter(new StringBuilderWriter(res)));
}
return res.toString();
}
示例13: writeToString
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
public String writeToString(File docFile) throws IOException, Docx4JException {
WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(docFile);
StringBuilderWriter output = new StringBuilderWriter();
try {
this.writeToWriter(wmlPackage, output);
} finally {
IOUtils.closeQuietly(output);
}
return output.toString();
}
示例14: extract
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
public String extract(File inputfile) throws Exception {
WordprocessingMLPackage wmlPackage = WordprocessingMLPackage.load(inputfile);
StringBuilderWriter output = new StringBuilderWriter();
try {
this.extract(wmlPackage, output);
} finally {
IOUtils.closeQuietly(output);
}
return output.toString();
}
示例15: clearlyShowError
import org.apache.commons.io.output.StringBuilderWriter; //导入依赖的package包/类
static void clearlyShowError(int attempt, Exception e, StringBuilderWriter buildLog, StringBuilderWriter consoleLog) throws Exception {
System.out.println("Failure on attempt " + attempt);
System.out.println("Build log");
System.out.println(buildLog);
System.out.println();
System.out.println("Console log");
System.out.println(consoleLog);
throw e;
}