本文整理汇总了Java中java.io.StringWriter.write方法的典型用法代码示例。如果您正苦于以下问题:Java StringWriter.write方法的具体用法?Java StringWriter.write怎么用?Java StringWriter.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.StringWriter
的用法示例。
在下文中一共展示了StringWriter.write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getStreamAsString
import java.io.StringWriter; //导入方法依赖的package包/类
private static String getStreamAsString(InputStream stream, String charset) throws IOException {
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(stream, charset));
StringWriter writer = new StringWriter();
char[] chars = new char[256];
int count = 0;
while ((count = reader.read(chars)) > 0) {
writer.write(chars, 0, count);
}
return writer.toString();
} finally {
if (stream != null) {
stream.close();
}
}
}
示例2: read
import java.io.StringWriter; //导入方法依赖的package包/类
public static String read(Reader reader) {
try {
StringWriter writer = new StringWriter();
char[] buffer = new char[DEFAULT_BUFFER_SIZE];
int n = 0;
while (-1 != (n = reader.read(buffer))) {
writer.write(buffer, 0, n);
}
return writer.toString();
} catch (IOException ex) {
throw new IllegalStateException("read error", ex);
}
}
示例3: convertStream
import java.io.StringWriter; //导入方法依赖的package包/类
/**
* Converts an input stream to a string.
*
* @param is
* @return
*/
public String convertStream(InputStream is) {
try {
StringWriter writer = new StringWriter();
for (int i = is.read(); i >= 0; i = is.read())
writer.write(i);
is.close();
return writer.toString();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例4: addSchemaFragmentJavadoc
import java.io.StringWriter; //导入方法依赖的package包/类
/**
* Copies a schema fragment into the javadoc of the generated class.
*/
private void addSchemaFragmentJavadoc( CClassInfo bean, XSComponent sc ) {
// first, pick it up from <documentation> if any.
String doc = builder.getBindInfo(sc).getDocumentation();
if(doc!=null)
append(bean, doc);
// then the description of where this component came from
Locator loc = sc.getLocator();
String fileName = null;
if(loc!=null) {
fileName = loc.getPublicId();
if(fileName==null)
fileName = loc.getSystemId();
}
if(fileName==null) fileName="";
String lineNumber=Messages.format( Messages.JAVADOC_LINE_UNKNOWN);
if(loc!=null && loc.getLineNumber()!=-1)
lineNumber = String.valueOf(loc.getLineNumber());
String componentName = sc.apply( new ComponentNameFunction() );
String jdoc = Messages.format( Messages.JAVADOC_HEADING, componentName, fileName, lineNumber );
append(bean,jdoc);
// then schema fragment
StringWriter out = new StringWriter();
out.write("<pre>\n");
SchemaWriter sw = new SchemaWriter(new JavadocEscapeWriter(out));
sc.visit(sw);
out.write("</pre>");
append(bean,out.toString());
}
示例5: addHexAscii
import java.io.StringWriter; //导入方法依赖的package包/类
static void addHexAscii(byte b, StringWriter sw) {
short ub = toUnsigned(b);
int h1 = ub / 16;
int h2 = ub % 16;
sw.write(toHexDigit(h1));
sw.write(toHexDigit(h2));
}
示例6: readFully
import java.io.StringWriter; //导入方法依赖的package包/类
/**
* Returns the remainder of 'reader' as a string, closing it when done.
*/
public static String readFully(Reader reader) throws IOException {
try {
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
return writer.toString();
} finally {
reader.close();
}
}
示例7: readFully
import java.io.StringWriter; //导入方法依赖的package包/类
/** Returns the remainder of 'reader' as a string, closing it when done. */
public static String readFully(Reader reader) throws IOException {
try {
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
return writer.toString();
} finally {
reader.close();
}
}
示例8: testOpenBufferedStream
import java.io.StringWriter; //导入方法依赖的package包/类
public void testOpenBufferedStream() throws IOException {
BufferedReader reader = source.openBufferedStream();
StringWriter writer = new StringWriter();
char[] buf = new char[64];
int read;
while ((read = reader.read(buf)) != -1) {
writer.write(buf, 0, read);
}
reader.close();
writer.close();
assertExpectedString(writer.toString());
}
示例9: readFully
import java.io.StringWriter; //导入方法依赖的package包/类
static String readFully(Reader reader) throws IOException {
try {
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
return writer.toString();
} finally {
reader.close();
}
}
示例10: readFile
import java.io.StringWriter; //导入方法依赖的package包/类
private static String readFile(File file) throws Exception {
Reader reader = new FileReader(file);
StringWriter writer = new StringWriter();
char[] buffer = new char[1024];
int count;
while ((count = reader.read(buffer)) != -1) {
writer.write(buffer, 0, count);
}
reader.close();
return writer.toString();
}
示例11: testOpenStream
import java.io.StringWriter; //导入方法依赖的package包/类
public void testOpenStream() throws IOException {
Reader reader = source.openStream();
StringWriter writer = new StringWriter();
char[] buf = new char[64];
int read;
while ((read = reader.read(buf)) != -1) {
writer.write(buf, 0, read);
}
reader.close();
writer.close();
assertExpectedString(writer.toString());
}
示例12: LogMessage
import java.io.StringWriter; //导入方法依赖的package包/类
/**
* Constructs an instance from a Log4J event, using the specified layout.
*
* @throws RuntimeException if any error occurred during formatting or conversion.
* Will include any root cause other than UnsupportedEncodingException.
*/
public LogMessage(LoggingEvent event, Layout layout)
{
try
{
StringWriter out = new StringWriter(1024);
out.write(layout.format(event));
if ((event.getThrowableInformation() != null) && layout.ignoresThrowable())
{
for (String traceline : event.getThrowableStrRep())
{
out.write(traceline);
out.write(Layout.LINE_SEP);
}
}
out.close();
this.timestamp = event.getTimeStamp();
this.message = out.toString();
this.messageBytes = this.message.getBytes("UTF-8");
}
catch (UnsupportedEncodingException e)
{
throw new RuntimeException("UnsupportedEncodingException when converting to UTF-8");
}
catch (Exception ex)
{
throw new RuntimeException("error creating LogMessage", ex);
}
}
示例13: process
import java.io.StringWriter; //导入方法依赖的package包/类
public boolean process(final SimpleRequest request, final SimpleResponse response)
throws IOException
{
RequestLine requestline = request.getRequestLine();
HttpVersion httpversion = requestline.getHttpVersion();
StringWriter buffer = new StringWriter(100);
buffer.write("Method type: ");
buffer.write(requestline.getMethod());
buffer.write("\r\n");
buffer.write("Requested resource: ");
buffer.write(requestline.getUri());
buffer.write("\r\n");
buffer.write("Protocol version: ");
buffer.write(httpversion.toString());
buffer.write("\r\n");
String requestbody = request.getBodyString();
if (requestbody != null && !requestbody.equals("")) {
buffer.write("\r\n");
buffer.write("Request body: ");
buffer.write(requestbody);
buffer.write("\r\n");
}
response.setStatusLine(httpversion, HttpStatus.SC_OK);
response.setBodyString(buffer.toString());
return true;
}
示例14: a
import java.io.StringWriter; //导入方法依赖的package包/类
public static String a(InputStream inputStream) throws IOException {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
char[] cArr = new char[1024];
StringWriter stringWriter = new StringWriter();
while (true) {
int read = inputStreamReader.read(cArr);
if (-1 == read) {
return stringWriter.toString();
}
stringWriter.write(cArr, 0, read);
}
}
示例15: formatResult
import java.io.StringWriter; //导入方法依赖的package包/类
private String formatResult(ClientResponse cr) {
final VoltTable results[] = cr.getResults();
final int num_results = results.length;
StringBuilder sb = new StringBuilder();
if (this.enable_debug) {
sb.append(cr.toString());
}
else {
// MAIN BODY
if (this.enable_csv) {
StringWriter out = new StringWriter();
for (int i = 0; i < num_results; i++) {
if (i > 0) out.write("\n\n");
VoltTableUtil.csv(out, results[i], true);
} // FOR
sb.append(out.toString());
} else {
sb.append(VoltTableUtil.format(results));
}
// FOOTER
String footer = "";
if (this.enable_csv == false) {
if (num_results == 1) {
int row_count = results[0].getRowCount();
footer = String.format("%d row%s in set", row_count, (row_count > 1 ? "s" : ""));
}
else if (num_results == 0) {
footer = "No results returned";
}
else {
footer = num_results + " tables returned";
}
sb.append(String.format("\n%s (%.2f sec)\n", footer, (cr.getClientRoundtrip() / 1000d)));
}
}
return (sb.toString());
}