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


Java CharArrayWriter.toCharArray方法代码示例

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


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

示例1: reformat

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/** Reformat a block of code.
* @param doc document to work with
* @param startOffset offset at which the formatting starts
* @param endOffset offset at which the formatting ends
* @return length of the reformatted code
*/
public int reformat(BaseDocument doc, int startOffset, int endOffset)
throws BadLocationException {
    LegacyFormattersProvider.pushFormattingContextDocument(doc);
    try {
        try {
            CharArrayWriter cw = new CharArrayWriter();
            Writer w = createWriter(doc, startOffset, cw);
            String originalString = doc.getText(startOffset, endOffset - startOffset);
            w.write(originalString);
            w.close();
            String out = new String(cw.toCharArray());
            if(!out.equals(originalString)){
                doc.remove(startOffset, endOffset - startOffset);
                doc.insertString(startOffset, out, null);
                return out.length();
            }else{
                //nothing changed
                return 0;
            }
        } catch (IOException e) {
            Utilities.annotateLoggable(e);
            return 0;
        }
    } finally {
        LegacyFormattersProvider.popFormattingContextDocument(doc);
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:34,代码来源:Formatter.java

示例2: toString

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 Builds the dockerfile to a string
 */
@Override
public String toString() {
    CharArrayWriter out = new CharArrayWriter();
    writeTo(out);
    return new String(out.toCharArray());
}
 
开发者ID:StuPro-TOSCAna,项目名称:TOSCAna,代码行数:10,代码来源:DockerfileBuilder.java

示例3: tests18

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * Create a PrintWriter and use to to send output via DriverManager.println
 * Validate that if you disable the writer, the output sent is not present
 */
@Test
public void tests18() throws Exception {
    CharArrayWriter cw = new CharArrayWriter();
    PrintWriter pw = new PrintWriter(cw);
    DriverManager.setLogWriter(pw);
    assertTrue(DriverManager.getLogWriter() == pw);

    DriverManager.println(results[0]);
    DriverManager.setLogWriter(null);
    assertTrue(DriverManager.getLogWriter() == null);
    DriverManager.println(noOutput);
    DriverManager.setLogWriter(pw);
    DriverManager.println(results[1]);
    DriverManager.println(results[2]);
    DriverManager.println(results[3]);
    DriverManager.setLogWriter(null);
    DriverManager.println(noOutput);

    /*
     * Check we do not get the output when the stream is disabled
     */
    BufferedReader reader
            = new BufferedReader(new CharArrayReader(cw.toCharArray()));
    for (String result : results) {
        assertTrue(result.equals(reader.readLine()));
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:32,代码来源:DriverManagerTests.java

示例4: resolveIncludes

import java.io.CharArrayWriter; //导入方法依赖的package包/类
public static BufferedReader resolveIncludes(BufferedReader reader, String filePath, IShaderPack shaderPack, int includeLevel) throws IOException
{
    String s = "/";
    int i = filePath.lastIndexOf("/");

    if (i >= 0)
    {
        s = filePath.substring(0, i);
    }

    CharArrayWriter chararraywriter = new CharArrayWriter();

    while (true)
    {
        String s1 = reader.readLine();

        if (s1 == null)
        {
            CharArrayReader chararrayreader = new CharArrayReader(chararraywriter.toCharArray());
            return new BufferedReader(chararrayreader);
        }

        Matcher matcher = PATTERN_INCLUDE.matcher(s1);

        if (matcher.matches())
        {
            String s2 = matcher.group(1);
            boolean flag = s2.startsWith("/");
            String s3 = flag ? "/shaders" + s2 : s + "/" + s2;
            s1 = loadFile(s3, shaderPack, includeLevel);

            if (s1 == null)
            {
                throw new IOException("Included file not found: " + filePath);
            }
        }

        chararraywriter.write(s1);
        chararraywriter.write("\n");
    }
}
 
开发者ID:SkidJava,项目名称:BaseClient,代码行数:42,代码来源:ShaderPackParser.java

示例5: toCharArray

import java.io.CharArrayWriter; //导入方法依赖的package包/类
public static char[] toCharArray(InputStream input) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    write(input, output);
    return output.toCharArray();
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:6,代码来源:IOUtils.java

示例6: toCharArray

import java.io.CharArrayWriter; //导入方法依赖的package包/类
public static char[] toCharArray(CharSequence input) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    write(input, output);
    return output.toCharArray();
}
 
开发者ID:coding-dream,项目名称:TPlayer,代码行数:6,代码来源:IOUtils.java

示例7: printMessage

import java.io.CharArrayWriter; //导入方法依赖的package包/类
private static void printMessage(boolean oneTimeOnly, String messageClass, String message,
		                         Throwable t, Object ... args)
{
	// TODO: Too much garbage collection
	for (int i = 0; i < args.length; i++)
	{
		if (args[i] != null)
		{
			message = message.replace("{" + i  + "}", args[i].toString());
		}
	}
	message += " ";
	
	if (oneTimeOnly) // One time messages logged only once!
	{
		if (oneTimeMessages.contains(message))
		{
			return;
		} else
		{
			oneTimeMessages.add(message);
		}
	}
	
	String prefix =
		"[" + Thread.currentThread().getName() + "] " +
	    "[" + (new Date()).toString() + "] ";
	
	messageClass = "[" + messageClass + "] ";
	
	String throwable = "";
	if (t != null)
	{
		CharArrayWriter car = new CharArrayWriter(500);
		PrintWriter pr = new PrintWriter(car);
		pr.println();  // One line extra before the exception.
		t.printStackTrace(pr);
		pr.close();
		throwable = new String(car.toCharArray()); 
	}
		
	System.out.println(prefix + messageClass + message + throwable);
	
	if (fileOut != null)
	{
		fileOut.println(prefix + messageClass + message + throwable);
		fileOut.flush();
	}
}
 
开发者ID:ZencashOfficial,项目名称:zencash-swing-wallet-ui,代码行数:50,代码来源:Log.java

示例8: encode

import java.io.CharArrayWriter; //导入方法依赖的package包/类
public static char[] encode(byte[] content) {
    CharArrayWriter cw = new CharArrayWriter((4 * content.length) / 3);

    int idx = 0;

    int x = 0;

    for (int i = 0; i < content.length; i++) {
        if (idx == 0)
            x = (content[i] & 0xff) << 16;
        else if (idx == 1)
            x = x | ((content[i] & 0xff) << 8);
        else
            x = x | (content[i] & 0xff);

        idx++;

        if (idx == 3) {
            cw.write(alphabet[x >> 18]);
            cw.write(alphabet[(x >> 12) & 0x3f]);
            cw.write(alphabet[(x >> 6) & 0x3f]);
            cw.write(alphabet[x & 0x3f]);

            idx = 0;
        }
    }

    if (idx == 1) {
        cw.write(alphabet[x >> 18]);
        cw.write(alphabet[(x >> 12) & 0x3f]);
        cw.write('=');
        cw.write('=');
    }

    if (idx == 2) {
        cw.write(alphabet[x >> 18]);
        cw.write(alphabet[(x >> 12) & 0x3f]);
        cw.write(alphabet[(x >> 6) & 0x3f]);
        cw.write('=');
    }

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

示例9: toCharArray

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * Get the contents of an <code>InputStream</code> as a character array
 * using the specified character encoding.
 * <p/>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 *
 * @param is       the <code>InputStream</code> to read from
 * @param encoding the encoding to use, null means platform default
 * @return the requested character array
 * @throws NullPointerException if the input is null
 * @throws IOException          if an I/O error occurs
 * @since 2.3
 */
public static char[] toCharArray(InputStream is, Charset encoding)
        throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    copy(is, output, encoding);
    return output.toCharArray();
}
 
开发者ID:wzx54321,项目名称:XinFramework,代码行数:21,代码来源:IOUtils.java

示例10: toCharArray

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * Get the contents of an <code>InputStream</code> as a character array
 * using the specified character encoding.
 * <p>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 * 
 * @param is  the <code>InputStream</code> to read from
 * @param encoding  the encoding to use, null means platform default
 * @return the requested character array
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @since 2.3
 */
public static char[] toCharArray(InputStream is, Charset encoding)
        throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    copy(is, output, encoding);
    return output.toCharArray();
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:21,代码来源:IOUtils.java

示例11: toCharArray

import java.io.CharArrayWriter; //导入方法依赖的package包/类
/**
 * Get the contents of an <code>InputStream</code> as a character array
 * using the default character encoding of the platform.
 * <p>
 * This method buffers the input internally, so there is no need to use a
 * <code>BufferedInputStream</code>.
 * 
 * @param is  the <code>InputStream</code> to read from
 * @return the requested character array
 * @throws NullPointerException if the input is null
 * @throws IOException if an I/O error occurs
 * @since Commons IO 1.1
 */
public static char[] toCharArray(InputStream is) throws IOException {
    CharArrayWriter output = new CharArrayWriter();
    copy(is, output);
    return output.toCharArray();
}
 
开发者ID:fesch,项目名称:Moenagade,代码行数:19,代码来源:IOUtils.java


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