/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#toCharArray(java.io.InputStream)} */ @Deprecated public static char[] toCharArray(InputStream is) throws IOException { return org.apache.commons.io.IOUtils.toCharArray(is); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#toCharArray(java.io.InputStream, String)} */ @Deprecated public static char[] toCharArray(InputStream is, String encoding) throws IOException { return org.apache.commons.io.IOUtils.toCharArray(is, encoding); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#toCharArray(java.io.Reader)} */ @Deprecated public static char[] toCharArray(Reader input) throws IOException { return org.apache.commons.io.IOUtils.toCharArray(input); }
/** * Gets 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 1.1 * @deprecated 2.5 use {@link #toCharArray(InputStream, Charset)} instead */ @Deprecated public static char[] toCharArray(final InputStream is) throws IOException { return toCharArray(is, Charset.defaultCharset()); }
/** * Gets 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 * @throws java.nio.charset.UnsupportedCharsetException thrown instead of {@link java.io * .UnsupportedEncodingException} in version 2.2 if the * encoding is not supported. * @since 1.1 */ public static char[] toCharArray(final InputStream is, final String encoding) throws IOException { return toCharArray(is, Charsets.toCharset(encoding)); }
@Test public void testToCharArray_InputStream_CharsetName() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final char[] out = IOUtils.toCharArray(fin, "UTF-8"); assertNotNull(out); assertEquals("Not all chars were read", 0, fin.available()); assertEquals("Wrong output size", FILE_SIZE, out.length); TestUtils.assertEqualContent(out, m_testFile); } }
@Test public void testToCharArray_InputStream() throws Exception { try (FileInputStream fin = new FileInputStream(m_testFile)) { final char[] out = IOUtils.toCharArray(fin); assertNotNull(out); assertEquals("Not all chars were read", 0, fin.available()); assertEquals("Wrong output size", FILE_SIZE, out.length); TestUtils.assertEqualContent(out, m_testFile); } }
@Test public void testToCharArray_Reader() throws Exception { try (FileReader fr = new FileReader(m_testFile)) { final char[] out = IOUtils.toCharArray(fr); assertNotNull(out); assertEquals("Wrong output size", FILE_SIZE, out.length); TestUtils.assertEqualContent(out, m_testFile); } }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#toCharArray(java.io.Reader)} */ @Deprecated public static char[] toCharArray(Reader input) throws IOException { return org.apache.commons.io.IOUtils.toCharArray(input); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#toCharArray(java.io.InputStream)} */ @Deprecated public static char[] toCharArray(InputStream is) throws IOException { return org.apache.commons.io.IOUtils.toCharArray(is); }
/** * @deprecated Use instead {@link org.apache.commons.io.IOUtils#toCharArray(java.io.InputStream, String)} */ @Deprecated public static char[] toCharArray(InputStream is, String encoding) throws IOException { return org.apache.commons.io.IOUtils.toCharArray(is, encoding); }
private static String readHttpServletRequestBody(final HttpServletRequest request) throws IOException { // If a previous section of code has grabbed data using getReader or getInput stream before the execution path // goes through this method then we need to use the same getter that the previous codepath used. This method // unfortunately needs to rely upon exceptions for logic to decide which is the correct getter to get the content // of this HttpServletRequest. try { return new String(IOUtils.toCharArray(request.getInputStream())); } catch (IllegalStateException e) { return new String(IOUtils.toCharArray(request.getReader())); } }
private static String readHttpServletRequestBody(final HttpServletRequest request) throws IOException { // If a previous section of code has grabbed data using getReader or getInput stream before the execution path // goes through this method then we need to use the same getter that the previous codepath used. This method // unfortunately needs to rely upon exceptions for logic to decide which is the correct getter to get the content // of this HttpServletRequest. try { return new String(IOUtils.toCharArray(request.getInputStream())); } catch (IllegalStateException e) { return new String(IOUtils.toCharArray(request.getReader())); } }
/** * 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 1.1 */ public static char[] toCharArray(InputStream is) throws IOException { return toCharArray(is, Charset.defaultCharset()); }
/** * Gets 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 1.1 * @deprecated 2.5 use {@link #toCharArray(InputStream, Charset)} instead */ @Deprecated public static char[] toCharArray(final InputStream is) throws IOException { return toCharArray(is, Charset.defaultCharset()); }
private static char[] fileToCharArray(File file, Charset charset) { FileInputStream is = null; try { is = new FileInputStream(file); return IOUtils.toCharArray(is, charset.name()); } catch (IOException e) { throw new RecognitionException(0, e.getMessage(), e); } finally { IOUtils.closeQuietly(is); } }
private ManifestEx(Resource resource) throws IOException { super(resource.getInputStream()); path = StringUtils.removeEnd(resource.getURL().getPath(), MANIFEST_PATH); for (String licFile : LICENSE_FILES) { Resource license = resource.createRelative(licFile); if (license.exists()) { String licText = new String(IOUtils.toCharArray(license.getInputStream(), StrUtil.CHARSET)); getMainAttributes().putValue("License", licText); break; } } } }
private void processFiles(Resource resource, String[] files, String attributeName) throws IOException { for (String file : files) { Resource res = resource.createRelative(file); if (res.exists()) { String text = new String(IOUtils.toCharArray(res.getInputStream(), StrUtil.UTF8)); getMainAttributes().putValue(attributeName, text); break; } } } }
public static char[] toCharArray(ActionContext actionContext) throws IOException { Thing self = actionContext.getObject("self"); Object input = self.doAction("getInput", actionContext); if(input instanceof InputStream){ String encoding = (String) self.doAction("getEncoding", actionContext); return IOUtils.toCharArray((InputStream) input, encoding); }else if(input instanceof Reader){ return IOUtils.toCharArray((Reader) input); }else{ throw new ActionException("Unsupport input " + input + ", action=" + self.getMetadata().getPath()); } }
public void setXmlString(String xmlString) throws IOException, SAXException, ParserConfigurationException { this.xmlString = xmlString; if(StringUtils.startsWith(xmlString, "file:") || StringUtils.startsWith(xmlString, "classpath:")) { ResourceEditor editor = new ResourceEditor(); editor.setAsText(xmlString); Resource resource = (Resource) editor.getValue(); xmlString = new String(IOUtils.toCharArray(resource.getInputStream())); } DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = dbf.newDocumentBuilder(); LOG.createAppender() .appendProperty("DocumentBuilderFactory class", dbf.getClass().getName()) .appendProperty("XPathFactory class", xPathFactory.getClass().getName()) .appendBold("XML String:") .appendXML(XMLFormatter.prettyPrint(xmlString)) .log(); this.document = db.parse(new InputSource(new StringReader(xmlString))); }