本文整理汇总了Java中org.apache.commons.io.output.StringBuilderWriter.toString方法的典型用法代码示例。如果您正苦于以下问题:Java StringBuilderWriter.toString方法的具体用法?Java StringBuilderWriter.toString怎么用?Java StringBuilderWriter.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.io.output.StringBuilderWriter
的用法示例。
在下文中一共展示了StringBuilderWriter.toString方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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();
}
示例3: 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();
}
示例4: transformDocument
import org.apache.commons.io.output.StringBuilderWriter; //导入方法依赖的package包/类
public static void transformDocument(File inputFile, File outputDir, boolean verbose) throws Exception {
StreamSource xhtmlHandlerSource = createStreamSource(RodimusCli.class.getResource("/rodimus.xsl"));
File indexFile = new File(outputDir, "index.html");
File assetDir = new File(outputDir, IMAGE_DIR_NAME);
assetDir.mkdirs();
// Set up the output buffer.
StringBuilderWriter output = new StringBuilderWriter();
// Set up the serializer.
ToXMLStream serializer = new ToXMLStream();
serializer.setOutputProperty(OutputPropertiesFactory.S_KEY_INDENT_AMOUNT,String.valueOf(2));
serializer.setOutputProperty(OutputPropertiesFactory.S_KEY_LINE_SEPARATOR,"\n");
serializer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputPropertiesFactory.S_KEY_ENTITIES, "yes");
serializer.setOutputProperty(OutputKeys.ENCODING, "US-ASCII");
serializer.setWriter(output);
// Set up the xhtmlStructure handler.
TransformerHandler xhtmlHandler = getContentHandler(xhtmlHandlerSource);
xhtmlHandler.setResult(new SAXResult(serializer));
// build the Tika handler.
ParseContext context = createParseContext(assetDir, verbose);
PostTikaHandler cleanUp = new PostTikaHandler(IMAGE_DIR_NAME);
cleanUp.setContentHandler(xhtmlHandler);
parseInput(createInputStream(inputFile), cleanUp, context, verbose);
// Do some regular expression cleanup.
String preOutput = output.toString();
preOutput = preOutput.replaceAll("/>", " />");
// TODO: img is in this list, but it is not a block level element.
String blockLevel = "(?:address|article|aside|audio|blockquote|canvas|dd|div|dl|fieldset|figcaption|figure|footer|form|h[1-6]|header|hgroup|hr|noscript|ol|output|p|pre|sectop|table|tfoot|ul|video|img)";
preOutput = preOutput.replaceAll("(</"+blockLevel+">)(\\s*)(<"+blockLevel+")", "$1$2$2$3");
preOutput = "<!doctype html>\n"+preOutput;
FileUtils.write(indexFile, preOutput, "UTF-8");
// Clean out images dir if it's empty
if (assetDir.list().length == 0) {
FileUtils.deleteQuietly(assetDir);
}
}
示例5: toString
import org.apache.commons.io.output.StringBuilderWriter; //导入方法依赖的package包/类
/**
* Get the contents of an <code>InputStream</code> as a String
* using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
*
* @param input the <code>InputStream</code> to read from
* @param encoding the encoding to use, null means platform default
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
*/
public static String toString(InputStream input, String encoding)
throws IOException {
StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw, encoding);
return sw.toString();
}
示例6: toString
import org.apache.commons.io.output.StringBuilderWriter; //导入方法依赖的package包/类
/**
* Get the contents of an <code>InputStream</code> as a String
* using the specified character encoding.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
* </p>
* @param input the <code>InputStream</code> to read from
* @param encoding the encoding to use, null means platform default
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since 2.3
*/
public static String toString(InputStream input, Charset encoding) throws IOException {
StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw, encoding);
return sw.toString();
}
示例7: toString
import org.apache.commons.io.output.StringBuilderWriter; //导入方法依赖的package包/类
/**
* Gets the contents of an <code>InputStream</code> as a String
* using the specified character encoding.
* <p>
* This method buffers the input internally, so there is no need to use a
* <code>BufferedInputStream</code>.
* </p>
*
* @param input the <code>InputStream</code> to read from
* @param encoding the encoding to use, null means platform default
* @return the requested String
* @throws NullPointerException if the input is null
* @throws IOException if an I/O error occurs
* @since 2.3
*/
public static String toString(final InputStream input, final Charset encoding) throws IOException {
final StringBuilderWriter sw = new StringBuilderWriter();
copy(input, sw, encoding);
return sw.toString();
}
示例8: toString
import org.apache.commons.io.output.StringBuilderWriter; //导入方法依赖的package包/类
/**
* Serialize the provided Patch to String.
* @param patch the patch to serialize
* @param namespaces the namespaces to use
* @return String representation of the given patch.
*/
public static String toString(List<PatchLine> patch, Map<String, String> namespaces) {
StringBuilderWriter sbw = new StringBuilderWriter();
writePatch(sbw, patch, namespaces);
return sbw.toString();
}