本文整理汇总了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);
}
}
示例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());
}
示例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()));
}
}
示例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");
}
}
示例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();
}
示例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();
}
示例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();
}
}
示例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();
}
示例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();
}
示例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();
}
示例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();
}