/** * Convert the specified CharSequence to an input stream, encoded as bytes * using the default character encoding of the platform. * * @param input the CharSequence to convert * @return an input stream * @since IO 2.0 */ public static InputStream toInputStream(CharSequence input) { return toInputStream(input.toString()); }
/** * Convert the specified CharSequence to an input stream, encoded as bytes * using the specified character encoding. * <p> * Character encoding names can be found at * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * * @param input the CharSequence to convert * @param encoding the encoding to use, null means platform default * @throws IOException if the encoding is invalid * @return an input stream * @since IO 2.0 */ public static InputStream toInputStream(CharSequence input, String encoding) throws IOException { return toInputStream(input.toString(), encoding); }
@Override public InputStream getInputStream() throws IOException { return IOUtils.toInputStream("Hello, World!", UTF_8.name()); } });
/** * Convert the specified CharSequence to an input stream, encoded as bytes * using the default character encoding of the platform. * * @param input the CharSequence to convert * @return an input stream * @since IO 2.0 */ public static InputStream toInputStream(CharSequence input) { return toInputStream(input.toString()); }
/** * Convert the specified CharSequence to an input stream, encoded as bytes * using the default character encoding of the platform. * * @param input the CharSequence to convert * @return an input stream * @since IO 2.0 */ public static InputStream toInputStream(CharSequence input) { return toInputStream(input.toString()); }
/** * Convert the specified CharSequence to an input stream, encoded as bytes * using the specified character encoding. * <p> * Character encoding names can be found at * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * * @param input the CharSequence to convert * @param encoding the encoding to use, null means platform default * @throws IOException if the encoding is invalid * @return an input stream * @since IO 2.0 */ public static InputStream toInputStream(CharSequence input, String encoding) throws IOException { return toInputStream(input.toString(), encoding); }
/** * Convert the specified CharSequence to an input stream, encoded as bytes * using the specified character encoding. * <p> * Character encoding names can be found at * <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * * @param input the CharSequence to convert * @param encoding the encoding to use, null means platform default * @throws IOException if the encoding is invalid * @return an input stream * @since IO 2.0 */ public static InputStream toInputStream(CharSequence input, String encoding) throws IOException { return toInputStream(input.toString(), encoding); }
@Test public void testStreamBased() throws IOException { InputStream input = IOUtils.toInputStream("Hello, World!", UTF_8.name()); TikaInputStream stream = TikaInputStream.get(input); assertFalse(stream.hasFile()); assertNull(stream.getOpenContainer()); assertNull(stream.getInputStreamFactory()); Path file = TikaInputStream.get(stream).getPath(); assertTrue(file != null && Files.isRegularFile(file)); assertTrue(stream.hasFile()); assertNull(stream.getOpenContainer()); assertNull(stream.getInputStreamFactory()); assertEquals( "The contents of the file returned by the getFile method" + " should equal the contents of the TikaInputStream", "Hello, World!", readFile(file)); assertEquals( "The contents of the TikaInputStream should not get modified" + " by reading the file first", "Hello, World!", readStream(stream)); stream.close(); assertFalse( "The close() method must remove the temporary file created" + " by a TikaInputStream", Files.exists(file)); }