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


Java CharArrayWriter.toString方法代码示例

本文整理汇总了Java中java.io.CharArrayWriter.toString方法的典型用法代码示例。如果您正苦于以下问题:Java CharArrayWriter.toString方法的具体用法?Java CharArrayWriter.toString怎么用?Java CharArrayWriter.toString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.CharArrayWriter的用法示例。


在下文中一共展示了CharArrayWriter.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: escapeCDATA

import java.io.CharArrayWriter; //导入方法依赖的package包/类
private String escapeCDATA(String text) {
    if( text==null ) return "";
    int len = text.length();
    CharArrayWriter result = new CharArrayWriter(len);
    for (int i=0; i<len; i++) {
        if (((i+2) < len)
                && (text.charAt(i) == ']')
                && (text.charAt(i+1) == ']')
                && (text.charAt(i+2) == '>')) {
            // match found
            result.write(']');
            result.write(']');
            result.write('&');
            result.write('g');
            result.write('t');
            result.write(';');
            i += 2;
        } else {
            result.write(text.charAt(i));
        }
    }
    return result.toString();
}
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:24,代码来源:PageDataImpl.java

示例2: main

import java.io.CharArrayWriter; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
    int N = 10;

    for (int i = 0; i < N; i++) {
        HTMLEditorKit kit = new HTMLEditorKit();
        Class c = Class.forName("javax.swing.text.html.parser.ParserDelegator");
        HTMLEditorKit.Parser parser = (HTMLEditorKit.Parser) c.newInstance();
        HTMLDocument doc = (HTMLDocument) kit.createDefaultDocument();
        HTMLEditorKit.ParserCallback htmlReader = doc.getReader(0);
        parser.parse(new CharArrayReader(htmlDoc.toCharArray()), htmlReader, true);
        htmlReader.flush();
        CharArrayWriter writer = new CharArrayWriter(1000);
        kit.write(writer, doc, 0, doc.getLength());
        writer.flush();

        String result = writer.toString();
        if (!result.contains("<tt><a")) {
            throw new RuntimeException("The <a> and <tt> tags are swapped");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:22,代码来源:bug8005391.java

示例3: parseScriptText

import java.io.CharArrayWriter; //导入方法依赖的package包/类
private String parseScriptText(String tx) {
    CharArrayWriter cw = new CharArrayWriter();
    int size = tx.length();
    int i = 0;
    while (i < size) {
        char ch = tx.charAt(i);
        if (i + 2 < size && ch == '%' && tx.charAt(i + 1) == '\\'
                && tx.charAt(i + 2) == '>') {
            cw.write('%');
            cw.write('>');
            i += 3;
        } else {
            cw.write(ch);
            ++i;
        }
    }
    cw.close();
    return cw.toString();
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:20,代码来源:Parser.java

示例4: binaryReader

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * 读取请求流
 * @param request
 * @return
 * @throws IOException
 */
public static String binaryReader(HttpServletRequest request) throws IOException {
    String charset = request.getCharacterEncoding();
    if (charset == null) {
        charset = "utf-8";
    }
    BufferedReader in = new BufferedReader(new InputStreamReader(request
            .getInputStream(), charset));

    // Read the request
    CharArrayWriter data = new CharArrayWriter();
    char[] buf = new char[8192];
    int ret;
    while ((ret = in.read(buf, 0, 8192)) != -1) {
        data.write(buf, 0, ret);
    }
    return data.toString();
}
 
开发者ID:yangjinhe,项目名称:maintain-robot,代码行数:24,代码来源:MyUtil.java

示例5: CRCCheck

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * Check if the CRC of the snapshot file matches the digest.
 * @param f The snapshot file object
 * @return The table list as a string
 * @throws IOException If CRC does not match
 */
public static String CRCCheck(File f) throws IOException {
    final FileInputStream fis = new FileInputStream(f);
    try {
        final BufferedInputStream bis = new BufferedInputStream(fis);
        ByteBuffer crcBuffer = ByteBuffer.allocate(4);
        if (4 != bis.read(crcBuffer.array())) {
            throw new EOFException("EOF while attempting to read CRC from snapshot digest");
        }
        final int crc = crcBuffer.getInt();
        final InputStreamReader isr = new InputStreamReader(bis, "UTF-8");
        CharArrayWriter caw = new CharArrayWriter();
        while (true) {
            int nextChar = isr.read();
            if (nextChar == -1) {
                throw new EOFException("EOF while reading snapshot digest");
            }
            if (nextChar == '\n') {
                break;
            }
            caw.write(nextChar);
        }
        String tableList = caw.toString();
        byte tableListBytes[] = tableList.getBytes("UTF-8");
        CRC32 tableListCRC = new CRC32();
        tableListCRC.update(tableListBytes);
        tableListCRC.update("\n".getBytes("UTF-8"));
        final int calculatedValue = (int)tableListCRC.getValue();
        if (crc != calculatedValue) {
            throw new IOException("CRC of snapshot digest did not match digest contents");
        }

        return tableList;
    } finally {
        try {
            if (fis != null)
                fis.close();
        } catch (IOException e) {}
    }
}
 
开发者ID:s-store,项目名称:s-store,代码行数:46,代码来源:SnapshotUtil.java

示例6: readLine

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * InputStreamReader를 통해 한줄을 읽어주는 메소드. 
 * BufferedReader를 사용하면 buffering되는 과정에서 binary file data를
 * 읽어버리는 경우가 발생할 위험이 있으므로, 직접 구현되었다.
 */
private String readLine() throws IOException
{
	CharArrayWriter caw = new CharArrayWriter(40);
	int buf;
	while( (buf=in.read())!=-1 )
	{
		if( buf=='\r' ) 
			continue;

		if( buf=='\n' )
			return caw.toString();
		caw.write( buf );
	}
	if( caw.size()!=0 )
		return caw.toString();
	return null;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:23,代码来源:VolatileDownloader.java

示例7: readTo

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/** Read a maximal string until delim is encountered (which will be removed from stream).
 * This impl reads only ASCII, for speed.
 * Newline conventions are normalized to Unix \n.
 * @return the read string, or null if the delim is not encountered before EOF.
 */
private String readTo(InputStream is, char delim) throws IOException {
    if (delim == 10) {
        // Not implemented - stream might have "foo\r\n" and we would
        // return "foo" and leave "\n" in the stream.
        throw new IOException("Not implemented"); // NOI18N
    }
    CharArrayWriter caw = new CharArrayWriter(100);
    boolean inNewline = false;
    while (true) {
        int c = is.read();
        if (c == -1) return null;
        if (c > 126) return null;
        if (c == 10 || c == 13) {
            // Normalize: s/[\r\n]+/\n/g
            if (inNewline) {
                continue;
            } else {
                inNewline = true;
                c = 10;
            }
        } else if (c < 32 && c != 9) {
            // Random control character!
            return null;
        } else {
            inNewline = false;
        }
        if (c == delim) {
            return caw.toString();
        } else {
            caw.write(c);
        }
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:39,代码来源:ModuleList.java

示例8: verifyWriterCorrect

import java.io.CharArrayWriter; //导入方法依赖的package包/类
private boolean verifyWriterCorrect() throws Exception {
    final String IDENTITY_XSLT_WITH_INDENT =
            "<xsl:stylesheet version='1.0' " + // NOI18N
            "xmlns:xsl='http://www.w3.org/1999/XSL/Transform' " + // NOI18N
            "xmlns:xalan='http://xml.apache.org/xslt' " + // NOI18N
            "exclude-result-prefixes='xalan'>" + // NOI18N
            "<xsl:output method='xml' indent='yes' xalan:indent-amount='4'/>" + // NOI18N
            "<xsl:template match='@*|node()'>" + // NOI18N
            "<xsl:copy>" + // NOI18N
            "<xsl:apply-templates select='@*|node()'/>" + // NOI18N
            "</xsl:copy>" + // NOI18N
            "</xsl:template>" + // NOI18N
            "</xsl:stylesheet>"; // NOI18N
    String data = "<root xmlns='root'/>"; // NOI18N
    Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(data)));
    doc.getDocumentElement().appendChild(doc.createElementNS("child", "child")); // NOI18N
    Transformer t = TransformerFactory.newInstance().newTransformer(
            new StreamSource(new StringReader(IDENTITY_XSLT_WITH_INDENT)));
    Source source = new DOMSource(doc);
    CharArrayWriter output = new CharArrayWriter();
    Result result = new StreamResult(output);
    t.transform(source, result);
    
    output.close();
    
    String text = output.toString();
    
    return text.indexOf("\"child\"") != (-1) || text.indexOf("'child'") != (-1); // NOI18N
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:AntProjectModule.java

示例9: getText

import java.io.CharArrayWriter; //导入方法依赖的package包/类
String getText(Mark start, Mark stop) throws JasperException {
	Mark oldstart = mark();
	reset(start);
	CharArrayWriter caw = new CharArrayWriter();
	while (!markEquals(stop)) {
		caw.write(nextChar());
	}
	caw.close();
	setCurrent(oldstart);
	return caw.toString();
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:12,代码来源:JspReader.java

示例10: getText

import java.io.CharArrayWriter; //导入方法依赖的package包/类
String getText(Mark start, Mark stop) throws JasperException {
    Mark oldstart = mark();
    reset(start);
    CharArrayWriter caw = new CharArrayWriter();
    while (!stop.equals(mark()))
        caw.write(nextChar());
    caw.close();
    reset(oldstart);
    return caw.toString();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:11,代码来源:JspReader.java

示例11: toStackTrace

import java.io.CharArrayWriter; //导入方法依赖的package包/类
public static String toStackTrace(Throwable error, int cutoff) {
  // default initial size is 32 chars
  CharArrayWriter buffer = new CharArrayWriter(8 * 1024);
  error.printStackTrace(new PrintWriter(buffer));
  return buffer.size() < cutoff ? buffer.toString()
      : buffer.toString().substring(0, cutoff);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:8,代码来源:ErrorPage.java

示例12: toString

import java.io.CharArrayWriter; //导入方法依赖的package包/类
static public String toString(Reader reader) throws IOException {
    CharArrayWriter sw = new CharArrayWriter();
    copy(reader, sw);
    return sw.toString();
}
 
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:6,代码来源:IOTinyUtils.java

示例13: toString

import java.io.CharArrayWriter; //导入方法依赖的package包/类
@Override
public String toString() {
    final CharArrayWriter writer = new CharArrayWriter();
    dump();
    return writer.toString();
}
 
开发者ID:limpoxe,项目名称:Android-DownloadManager,代码行数:7,代码来源:DownloadInfo.java

示例14: parseTemplateText

import java.io.CharArrayWriter; //导入方法依赖的package包/类
private void parseTemplateText(Node parent) throws JasperException {

        if (!reader.hasMoreInput())
            return;

        CharArrayWriter ttext = new CharArrayWriter();

        int ch = reader.nextChar();
        while (ch != -1) {
            if (ch == '<') {
                // Check for "<\%"
                if (reader.peekChar(0) == '\\' && reader.peekChar(1) == '%') {
                    ttext.write(ch);
                    // Swallow the \
                    reader.nextChar();
                    ttext.write(reader.nextChar());
                } else {
                    if (ttext.size() == 0) {
                        ttext.write(ch);
                    } else {
                        reader.pushChar();
                        break;
                    }
                }
            } else if (ch == '\\' && !pageInfo.isELIgnored()) {
                int next = reader.peekChar(0);
                if (next == '$' || next == '#') {
                    ttext.write(reader.nextChar());
                } else {
                    ttext.write(ch);
                }
            } else if ((ch == '$' || ch == '#' && !pageInfo.isDeferredSyntaxAllowedAsLiteral()) &&
                    !pageInfo.isELIgnored()) {
                if (reader.peekChar(0) == '{') {
                    reader.pushChar();
                    break;
                } else {
                    ttext.write(ch);
                }
            } else {
                ttext.write(ch);
            }
            ch = reader.nextChar();
        }

        @SuppressWarnings("unused")
        Node unused = new Node.TemplateText(ttext.toString(), start, parent);
    }
 
开发者ID:sunmingshuai,项目名称:apache-tomcat-7.0.73-with-comment,代码行数:49,代码来源:Parser.java

示例15: encode

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * Encode byte array it into Java identifier string, i.e., a string that
 * only contains the following characters: (a, ... z, A, ... Z, 0, ... 9, _,
 * $). The encoding algorithm itself is not too clever: if the current
 * byte's ASCII value already is a valid Java identifier part, leave it as
 * it is. Otherwise it writes the escape character($) followed by:
 *
 * <ul>
 * <li> the ASCII value as a hexadecimal string, if the value is not in the
 * range 200..247</li>
 * <li>a Java identifier char not used in a lowercase hexadecimal string, if
 * the value is in the range 200..247</li>
 * </ul>
 *
 * <p>
 * This operation inflates the original byte array by roughly 40-50%</p>
 *
 * @param bytes the byte array to convert
 * @param compress use gzip to minimize string
 *
 * @throws IOException if there's a gzip exception
 */
public static String encode(byte[] bytes, final boolean compress) throws IOException {
    if (compress) {
        try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
                GZIPOutputStream gos = new GZIPOutputStream(baos)) {
            gos.write(bytes, 0, bytes.length);
            bytes = baos.toByteArray();
        }
    }
    final CharArrayWriter caw = new CharArrayWriter();
    try (JavaWriter jw = new JavaWriter(caw)) {
        for (final byte b : bytes) {
            final int in = b & 0x000000ff; // Normalize to unsigned
            jw.write(in);
        }
    }
    return caw.toString();
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:40,代码来源:Utility.java


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