use of java.io.CharArrayWriter in project sling by apache.
the class JspReader method getText.
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();
}
use of java.io.CharArrayWriter in project tika by apache.
the class IOUtils method toCharArray.
// read char[]
//-----------------------------------------------------------------------
/**
* 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();
}
use of java.io.CharArrayWriter in project tika by apache.
the class IOUtils method toCharArray.
/**
* Get the contents of an <code>InputStream</code> as a character array
* using the specified character encoding.
* <p>
* Character encoding names can be found at
* <a href="http://www.iana.org/assignments/character-sets">IANA</a>.
* <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 Commons IO 1.1
*/
public static char[] toCharArray(InputStream is, String encoding) throws IOException {
CharArrayWriter output = new CharArrayWriter();
copy(is, output, encoding);
return output.toCharArray();
}
use of java.io.CharArrayWriter in project tika by apache.
the class MagicDetector method decodeString.
private static byte[] decodeString(String value, String type) {
if (value.startsWith("0x")) {
byte[] vals = new byte[(value.length() - 2) / 2];
for (int i = 0; i < vals.length; i++) {
vals[i] = (byte) Integer.parseInt(value.substring(2 + i * 2, 4 + i * 2), 16);
}
return vals;
}
CharArrayWriter decoded = new CharArrayWriter();
for (int i = 0; i < value.length(); i++) {
if (value.charAt(i) == '\\') {
if (value.charAt(i + 1) == '\\') {
decoded.write('\\');
i++;
} else if (value.charAt(i + 1) == 'x') {
decoded.write(Integer.parseInt(value.substring(i + 2, i + 4), 16));
i += 3;
} else if (value.charAt(i + 1) == 'r') {
decoded.write((int) '\r');
i++;
} else if (value.charAt(i + 1) == 'n') {
decoded.write((int) '\n');
i++;
} else {
int j = i + 1;
while ((j < i + 4) && (j < value.length()) && (Character.isDigit(value.charAt(j)))) {
j++;
}
decoded.write(Short.decode("0" + value.substring(i + 1, j)).byteValue());
i = j - 1;
}
} else {
decoded.write(value.charAt(i));
}
}
// Now turn the chars into bytes
char[] chars = decoded.toCharArray();
byte[] bytes;
if ("unicodeLE".equals(type)) {
bytes = new byte[chars.length * 2];
for (int i = 0; i < chars.length; i++) {
bytes[i * 2] = (byte) (chars[i] & 0xff);
bytes[i * 2 + 1] = (byte) (chars[i] >> 8);
}
} else if ("unicodeBE".equals(type)) {
bytes = new byte[chars.length * 2];
for (int i = 0; i < chars.length; i++) {
bytes[i * 2] = (byte) (chars[i] >> 8);
bytes[i * 2 + 1] = (byte) (chars[i] & 0xff);
}
} else {
// Copy with truncation
bytes = new byte[chars.length];
for (int i = 0; i < bytes.length; i++) {
bytes[i] = (byte) chars[i];
}
}
return bytes;
}
use of java.io.CharArrayWriter in project jgnash by ccavanaugh.
the class MessageBusClient method sendRemoteMessage.
synchronized void sendRemoteMessage(final Message message) {
CharArrayWriter writer = new CharArrayWriter();
xstream.marshal(message, new CompactWriter(writer));
sendRemoteMessage(writer.toString());
logger.log(Level.FINE, "sent: {0}", writer.toString());
}
Aggregations