/** * Get the underlying character array or <code>null</code> if * writer not used. */ public char[] toCharArray() { if (writer == null) { return null; } return writer.toCharArray(); }
/** * Returns buffered writer content as char array. * Returns <code>null</code> if writer is not used. */ public char[] toCharArray() { if (bufferedWriter != null) { return bufferedWriter.toCharArray(); } return null; }
/** * @see java.io.CharArrayWriter#toString() */ @Override public String toString() { return new String(toCharArray()); } }
/** * @see CharArrayWriter#toString() */ @Override public String toString() { return new String(toCharArray()); } }
/** * @see #copy(InputStream, String, int) */ public static char[] readChars(final InputStream input, final String encoding, final int count) throws IOException { return copy(input, encoding, count).toCharArray(); }
/** * Invokes Lagarto parser with provided set of adapters * and returns processed content. */ public char[] invokeLagarto(final TagAdapter tagAdapter) { lagartoParser.parse(tagAdapter); return fastCharArrayWriter.toCharArray(); }
/** * @see #copy(Reader, int) */ public static char[] readChars(final Reader input, final int count) throws IOException { return copy(input, count).toCharArray(); }
public static char[] readChars(Reader input, int charCount) throws IOException { FastCharArrayWriter output = new FastCharArrayWriter(); copy(input, output, charCount); return output.toCharArray(); }
public static char[] readChars(InputStream input, int charCount) throws IOException { FastCharArrayWriter output = new FastCharArrayWriter(); copy(input, output, charCount); return output.toCharArray(); }
public static char[] readChars(Reader input) throws IOException { FastCharArrayWriter output = new FastCharArrayWriter(); copy(input, output); return output.toCharArray(); } public static char[] readChars(Reader input, int charCount) throws IOException {
public static char[] readChars(InputStream input) throws IOException { FastCharArrayWriter output = new FastCharArrayWriter(); copy(input, output); return output.toCharArray(); } public static char[] readChars(InputStream input, int charCount) throws IOException {
public static char[] readChars(InputStream input, String encoding) throws IOException { FastCharArrayWriter output = new FastCharArrayWriter(); copy(input, output, encoding); return output.toCharArray(); } public static char[] readChars(InputStream input, String encoding, int charCount) throws IOException {
public static char[] readChars(InputStream input, String encoding, int charCount) throws IOException { FastCharArrayWriter output = new FastCharArrayWriter(); copy(input, output, encoding, charCount); return output.toCharArray(); }
/** * Renders tag body to char array. */ public static char[] renderBody(final JspFragment body) throws JspException { FastCharArrayWriter writer = new FastCharArrayWriter(); invokeBody(body, writer); return writer.toCharArray(); }
/** * Reads file content as char array. */ public static char[] readChars(File file, String encoding) throws IOException { if (!file.exists()) { throw new FileNotFoundException(MSG_NOT_FOUND + file); } if (!file.isFile()) { throw new IOException(MSG_NOT_A_FILE + file); } long len = file.length(); if (len >= Integer.MAX_VALUE) { len = Integer.MAX_VALUE; } InputStream in = null; try { in = new FileInputStream(file); if (encoding.startsWith("UTF")) { in = new UnicodeInputStream(in, encoding); } FastCharArrayWriter fastCharArrayWriter = new FastCharArrayWriter((int) len); StreamUtil.copy(in, fastCharArrayWriter, encoding); return fastCharArrayWriter.toCharArray(); } finally { StreamUtil.close(in); } }
/** * Reads UTF file content as char array. * @see UnicodeInputStream */ public static char[] readUTFChars(File file) throws IOException { if (!file.exists()) { throw new FileNotFoundException(MSG_NOT_FOUND + file); } if (!file.isFile()) { throw new IOException(MSG_NOT_A_FILE + file); } long len = file.length(); if (len >= Integer.MAX_VALUE) { len = Integer.MAX_VALUE; } UnicodeInputStream in = null; try { in = new UnicodeInputStream(new FileInputStream(file), null); FastCharArrayWriter fastCharArrayWriter = new FastCharArrayWriter((int) len); String encoding = in.getDetectedEncoding(); if (encoding == null) { encoding = StringPool.UTF_8; } StreamUtil.copy(in, fastCharArrayWriter, encoding); return fastCharArrayWriter.toCharArray(); } finally { StreamUtil.close(in); } }
@Test void testFcat() throws IOException { FastCharArrayWriter fcaw = new FastCharArrayWriter(); fcaw.write(65); fcaw.write(new char[]{'a', 'z', 'r'}); fcaw.write(new char[]{'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l'}, 4, 3); char[] result = fcaw.toCharArray(); char[] expected = new char[]{'A', 'a', 'z', 'r', 'g', 'h', 'j'}; assertTrue(Arrays.equals(expected, result)); }
@Test void testFcatSingle() throws IOException { FastCharArrayWriter fcaw = new FastCharArrayWriter(); fcaw.write(73); fcaw.write(74); fcaw.write(75); fcaw.write(76); fcaw.write(77); char[] result = fcaw.toCharArray(); char[] expected = new char[]{73, 74, 75, 76, 77}; assertTrue(Arrays.equals(expected, result)); }
/** * Invokes Lagarto parser with provided set of adapters * and returns processed content. */ public char[] invokeLagarto(final TagAdapter tagAdapter) { lagartoParser.parse(tagAdapter); return fastCharArrayWriter.toCharArray(); }
/** * Invokes Lagarto parser with provided set of adapters * and returns processed content. */ public char[] invokeLagarto(TagAdapter tagAdapter) { lagartoParser.parse(tagAdapter); return fastCharArrayWriter.toCharArray(); }