當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。