/** * Closes the underlying <code>Reader</code> quietly. * This method is useful if you only want to process the first few * lines of a larger file. If you do not close the iterator * then the <code>Reader</code> remains open. * This method can safely be called multiple times. */ public void close() { finished = true; IOUtils.closeQuietly(bufferedReader); cachedLine = null; }
public ByteArrayImageProvider( InputStream imageStream, boolean useImageSize ) throws IOException { this( imageStream != null ? IOUtils.toByteArray( imageStream ) : null, useImageSize ); }
public void write( OutputStream output ) throws IOException { IOUtils.write( imageByteArray, output ); }
public void write( OutputStream outputStream ) throws IOException { InputStream inputStream = null; try { inputStream = getInputStream(); IOUtils.copy( inputStream, outputStream ); } finally { IOUtils.closeQuietly( inputStream ); } }
if ( method == ZipEntry.STORED ) byte[] inputBytes = IOUtils.toByteArray( entryInputStream ); CRC32 crc = new CRC32(); crc.update( inputBytes ); zipEntry.setCompressedSize( inputBytes.length ); zipOutputStream.putNextEntry( zipEntry ); IOUtils.write( inputBytes, zipOutputStream ); IOUtils.copy( entryInputStream, zipOutputStream ); IOUtils.closeQuietly( entryInputStream ); zipOutputStream.closeEntry();
/** * Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code> 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>. * <p> * This method uses {@link InputStreamReader}. * * @param input the <code>InputStream</code> to read from * @param output the <code>Writer</code> to write to * @throws NullPointerException if the input or output is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static void copy( InputStream input, Writer output ) throws IOException { InputStreamReader in = new InputStreamReader( input ); copy( in, output ); }
public static void generateJSONFile( IXDocReport report, IContext context, boolean upperCaseFirstChar, IContext dumpContext, File srcDir ) throws IOException { String jsonFileName = getJSONFileName( report, dumpContext ); JSONObject jsonObject = new JSONObject( context.getContextMap(), upperCaseFirstChar ); File jsonFile = new File( srcDir, jsonFileName ); jsonFile.getParentFile().mkdirs(); Writer jsonWriter = null; try { jsonWriter = new FileWriter( jsonFile ); String json = jsonObject.toString( 1 ); IOUtils.write( json, jsonWriter ); } finally { if ( jsonWriter != null ) { IOUtils.closeQuietly( jsonWriter ); } } }
IOUtils.copyLarge( input, output ); IOUtils.closeQuietly( input ); IOUtils.closeQuietly( output );
public static boolean isODP(XDocArchive documentArchive) { try { if (!documentArchive.hasEntry(MIMETYPE)) { return false; } return ODP_MIMETYPE.equals(IOUtils.toString(documentArchive .getEntryReader(MIMETYPE))); } catch (IOException e) { } return false; }
/** * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * <p> * Large streams (over 2GB) will return a bytes copied value of <code>-1</code> after the copy has completed since * the correct number of bytes cannot be returned as an int. For large streams use the * <code>copyLarge(InputStream, OutputStream)</code> method. * * @param input the <code>InputStream</code> to read from * @param output the <code>OutputStream</code> to write to * @return the number of bytes copied * @throws NullPointerException if the input or output is null * @throws IOException if an I/O error occurs * @throws ArithmeticException if the byte count is too large * @since Commons IO 1.1 */ public static int copy( InputStream input, OutputStream output ) throws IOException { long count = copyLarge( input, output ); if ( count > Integer.MAX_VALUE ) { return -1; } return (int) count; }
/** * Get the contents of an <code>InputStream</code> as a list of Strings, one entry per line, 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 input the <code>InputStream</code> to read from, not null * @return the list of Strings, never null * @throws NullPointerException if the input is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static List<String> readLines( InputStream input ) throws IOException { InputStreamReader reader = new InputStreamReader( input ); return readLines( reader ); }
writeLines( lines, lineEnding, output );
byte[] inputBytes = IOUtils.toByteArray(entryInputStream); CRC32 crc = new CRC32(); crc.update(inputBytes); zipEntry.setCompressedSize(inputBytes.length); zipOutputStream.putNextEntry(zipEntry); IOUtils.write(inputBytes, zipOutputStream); } else { zipOutputStream.putNextEntry(zipEntry); IOUtils.copy(entryInputStream, zipOutputStream); IOUtils.closeQuietly(entryInputStream); zipOutputStream.closeEntry();
/** * Copy bytes from an <code>InputStream</code> to chars on a <code>Writer</code> using the specified character * encoding. * <p> * This method buffers the input internally, so there is no need to use a <code>BufferedInputStream</code>. * <p> * Character encoding names can be found at <a href="http://www.iana.org/assignments/character-sets">IANA</a>. * <p> * This method uses {@link InputStreamReader}. * * @param input the <code>InputStream</code> to read from * @param output the <code>Writer</code> to write to * @param encoding the encoding to use, null means platform default * @throws NullPointerException if the input or output is null * @throws IOException if an I/O error occurs * @since Commons IO 1.1 */ public static void copy( InputStream input, Writer output, String encoding ) throws IOException { if ( encoding == null ) { copy( input, output ); } else { InputStreamReader in = new InputStreamReader( input, encoding ); copy( in, output ); } }
public void upload( BinaryData data ) throws ResourcesException { String resourceId = data.getResourceId(); byte[] input = data.getContent(); String resourcePath = getResourcePath( resourceId ); File file = new File( getRootFolder(), resourcePath ); if ( !file.getParentFile().exists() ) { file.getParentFile().mkdirs(); } OutputStream output = null; try { output = new FileOutputStream( file ); IOUtils.write( input, output ); } catch ( IOException e ) { throw new ResourcesException( e ); } finally { if ( output != null ) { IOUtils.closeQuietly( output ); } } }
public static void generateDocumentFile( IXDocReport report, InputStream documentIn, IContext dumpContext, File srcDir ) throws FileNotFoundException, IOException { String documentFileName = getDocumentFileName( report, dumpContext ); File documentFile = new File( srcDir, documentFileName ); documentFile.getParentFile().mkdirs(); OutputStream documentOut = null; try { documentOut = new FileOutputStream( documentFile ); IOUtils.copy( documentIn, documentOut ); } finally { if ( documentOut != null ) { IOUtils.closeQuietly( documentOut ); } } }
/** * Returns Reader to use for process template merge. * * @param reader * @return * @throws IOException */ private Reader getReader(Reader reader) throws IOException { if (forceModifyReader && isEscapeTemplate()) { // reader must be modify and escape must be done (add [#escape... at // first of the template StringBuilder newTemplate = new StringBuilder( formatter.getStartDocumentDirective()); String oldTemplate = IOUtils.toString(reader); newTemplate.append(oldTemplate); newTemplate.append(formatter.getEndDocumentDirective()); return new StringReader(newTemplate.toString()); } return reader; }
long count = copyLarge(input, output); if (count > Integer.MAX_VALUE) { return -1;
/** * Get the contents of an <code>InputStream</code> as a list of Strings, one * entry per line, 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 input * the <code>InputStream</code> to read from, not null * @return the list of Strings, never null * @throws NullPointerException * if the input is null * @throws IOException * if an I/O error occurs * @since Commons IO 1.1 */ public static List<String> readLines(InputStream input) throws IOException { InputStreamReader reader = new InputStreamReader(input); return readLines(reader); }
OutputStream output, String encoding) throws IOException { if (encoding == null) { writeLines(lines, lineEnding, output); } else { if (lines == null) {