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


Java StringWriter.write方法代码示例

本文整理汇总了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();
        }
    }
}
 
开发者ID:1991wangliang,项目名称:pay,代码行数:19,代码来源:WebUtils.java

示例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);
    }
}
 
开发者ID:yrain,项目名称:smart-cache,代码行数:17,代码来源:Utils.java

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

示例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());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:37,代码来源:ClassSelector.java

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

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

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

示例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());
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:15,代码来源:CharSourceTester.java

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

示例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();
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:12,代码来源:DiskLruCacheTest.java

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

示例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);
    }
}
 
开发者ID:kdgregory,项目名称:log4j-aws-appenders,代码行数:36,代码来源:LogMessage.java

示例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;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:30,代码来源:FeedbackService.java

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

示例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());
}
 
开发者ID:s-store,项目名称:sstore-soft,代码行数:40,代码来源:SStoreTerminal.java


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