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


Java CharArrayWriter类代码示例

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


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

示例1: filterWriter

import java.io.CharArrayWriter; //导入依赖的package包/类
@Override
public Writer filterWriter(final Writer w) {
    return new CharArrayWriter() {
        @Override
        public void close() {
            try {
                super.close();
                for (String line : new String(toCharArray()).split("\n")) {
                    w.write("t" + line);
                    w.write(System.getProperty("line.separator"));
                }
                w.close();
            } catch (IOException ex) {
                throw new IllegalStateException(ex);
            }
        }
    };
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:19,代码来源:ModificationResultTest.java

示例2: 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:how2j,项目名称:lazycat,代码行数:23,代码来源:PageDataImpl.java

示例3: 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,项目名称:sstore-soft,代码行数:46,代码来源:SnapshotUtil.java

示例4: 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:how2j,项目名称:lazycat,代码行数:19,代码来源:Parser.java

示例5: initWebXml

import java.io.CharArrayWriter; //导入依赖的package包/类
protected void initWebXml() {
	try {
		if (webxmlLevel >= INC_WEBXML) {
			mapout = openWebxmlWriter(new File(webxmlFile));
			servletout = new CharArrayWriter();
			mappingout = new CharArrayWriter();
		} else {
			mapout = null;
			servletout = null;
			mappingout = null;
		}
		if (webxmlLevel >= ALL_WEBXML) {
			mapout.write(Localizer.getMessage("jspc.webxml.header"));
			mapout.flush();
		} else if ((webxmlLevel >= INC_WEBXML) && !addWebXmlMappings) {
			mapout.write(Localizer.getMessage("jspc.webinc.header"));
			mapout.flush();
		}
	} catch (IOException ioe) {
		mapout = null;
		servletout = null;
		mappingout = null;
	}
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:25,代码来源:JspC.java

示例6: initWebXml

import java.io.CharArrayWriter; //导入依赖的package包/类
protected void initWebXml() {
    try {
        if (webxmlLevel >= INC_WEBXML) {
            mapout = openWebxmlWriter(new File(webxmlFile));
            servletout = new CharArrayWriter();
            mappingout = new CharArrayWriter();
        } else {
            mapout = null;
            servletout = null;
            mappingout = null;
        }
        if (webxmlLevel >= ALL_WEBXML) {
            mapout.write(Localizer.getMessage("jspc.webxml.header"));
            mapout.flush();
        } else if ((webxmlLevel>= INC_WEBXML) && !addWebXmlMappings) {
            mapout.write(Localizer.getMessage("jspc.webinc.header"));
            mapout.flush();
        }
    } catch (IOException ioe) {
        mapout = null;
        servletout = null;
        mappingout = null;
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:25,代码来源:JspC.java

示例7: 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

示例8: 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:liaokailin,项目名称:tomcat7,代码行数:24,代码来源:PageDataImpl.java

示例9: toCharArrayWriter

import java.io.CharArrayWriter; //导入依赖的package包/类
public CharArrayWriter toCharArrayWriter(String prefix) {
    CharArrayWriter buffer = new CharArrayWriter(100);

    final char delimiter = DEFAULT_DELIMITER;
    final String replaceDelimiter = DEFAULT_REPLACE_DELIMITER;

    if (prefix != null && !prefix.isEmpty()) {
        buffer.append(prefix);
    }

    buffer.append(replaceDelimiter(userId(), delimiter, replaceDelimiter)).append(delimiter);
    buffer.append(replaceDelimiter(eventType(), delimiter, replaceDelimiter))
            .append(delimiter);
    buffer.append(replaceDelimiter(date(), delimiter, replaceDelimiter)).append(delimiter);
    buffer.append(replaceDelimiter(time(), delimiter, replaceDelimiter)).append(delimiter);
    buffer.append(replaceDelimiter(status(), delimiter, replaceDelimiter)).append(delimiter);
    buffer.append(replaceDelimiter(origination(), delimiter, replaceDelimiter))
            .append(delimiter);
    buffer.append(replaceDelimiter(affectedResource(), delimiter, replaceDelimiter));

    return buffer;
}
 
开发者ID:xipki,项目名称:xitk,代码行数:23,代码来源:PciAuditEvent.java

示例10: logEvent0

import java.io.CharArrayWriter; //导入依赖的package包/类
@Override
protected void logEvent0(PciAuditEvent event) {
    CharArrayWriter msg = event.toCharArrayWriter("");
    AuditLevel al = event.level();
    switch (al) {
    case DEBUG:
        if (LOG.isDebugEnabled()) {
            LOG.debug("{} | {}", al.alignedText(), msg);
        }
        break;
    default:
        if (LOG.isInfoEnabled()) {
            LOG.info("{} | {}", al.alignedText(), msg);
        }
        break;
    } // end switch
}
 
开发者ID:xipki,项目名称:xitk,代码行数:18,代码来源:Slf4jAuditServiceImpl.java

示例11: initWebXml

import java.io.CharArrayWriter; //导入依赖的package包/类
protected void initWebXml() {
    try {
        if (webxmlLevel >= INC_WEBXML) {
            File fmapings = new File(webxmlFile);
            mapout = new FileWriter(fmapings);
            servletout = new CharArrayWriter();
            mappingout = new CharArrayWriter();
        } else {
            mapout = null;
            servletout = null;
            mappingout = null;
        }
        if (webxmlLevel >= ALL_WEBXML) {
            mapout.write(Localizer.getMessage("jspc.webxml.header"));
            mapout.flush();
        } else if ((webxmlLevel>= INC_WEBXML) && !addWebXmlMappings) {
            mapout.write(Localizer.getMessage("jspc.webinc.header"));
            mapout.flush();
        }
    } catch (IOException ioe) {
        mapout = null;
        servletout = null;
        mappingout = null;
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:26,代码来源:JspC.java

示例12: 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:lamsfoundation,项目名称:lams,代码行数:24,代码来源:PageDataImpl.java

示例13: log

import java.io.CharArrayWriter; //导入依赖的package包/类
/**
 * Writes an explanatory message and a stack trace for a given
 * <code>Throwable</code> exception to the servlet log file.  The name
 * and type of the servlet log file is specific to the servlet container,
 * usually an event log.  This message will be logged unconditionally.
 *
 * @param msg A <code>String</code> that describes the error or
 *  exception
 * @param throwable The <code>Throwable</code> error or exception
 */
public void log(String msg, Throwable throwable) {

    CharArrayWriter buf = new CharArrayWriter();
    PrintWriter writer = new PrintWriter(buf);
    writer.println(msg);
    throwable.printStackTrace(writer);
    Throwable rootCause = null;
    if (throwable instanceof LifecycleException)
        rootCause = ((LifecycleException) throwable).getThrowable();
    else if (throwable instanceof ServletException)
        rootCause = ((ServletException) throwable).getRootCause();
    if (rootCause != null) {
        writer.println("----- Root Cause -----");
        rootCause.printStackTrace(writer);
    }
    log(buf.toString());

}
 
开发者ID:c-rainstorm,项目名称:jerrydog,代码行数:29,代码来源:LoggerBase.java

示例14: authenticateWithPublicKey

import java.io.CharArrayWriter; //导入依赖的package包/类
/**
 * A convenience wrapper function which reads in a private key (PEM format, either DSA or RSA)
 * and then calls <code>authenticateWithPublicKey(String, char[], String)</code>.
 * <p>
 * NOTE PUTTY USERS: Event though your key file may start with "-----BEGIN..."
 * it is not in the expected format. You have to convert it to the OpenSSH
 * key format by using the "puttygen" tool (can be downloaded from the Putty
 * website). Simply load your key and then use the "Conversions/Export OpenSSH key"
 * functionality to get a proper PEM file.
 *
 * @param user     A <code>String</code> holding the username.
 * @param pemFile  A <code>File</code> object pointing to a file containing a DSA or RSA
 *                 private key of the user in OpenSSH key format (PEM, you can't miss the
 *                 "-----BEGIN DSA PRIVATE KEY-----" or "-----BEGIN RSA PRIVATE KEY-----"
 *                 tag).
 * @param password If the PEM file is encrypted then you must specify the password.
 *                 Otherwise, this argument will be ignored and can be set to <code>null</code>.
 * @return whether the connection is now authenticated.
 * @throws IOException
 */
public synchronized boolean authenticateWithPublicKey(String user, File pemFile, String password)
        throws IOException {
    if (pemFile == null)
        throw new IllegalArgumentException("pemFile argument is null");

    char[] buff = new char[256];

    CharArrayWriter cw = new CharArrayWriter();

    FileReader fr = new FileReader(pemFile);

    while (true) {
        int len = fr.read(buff);
        if (len < 0)
            break;
        cw.write(buff, 0, len);
    }

    fr.close();

    return authenticateWithPublicKey(user, cw.toCharArray(), password);
}
 
开发者ID:fast-data-transfer,项目名称:fdt,代码行数:43,代码来源:Connection.java

示例15: 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


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