try OutputStream out = new FileOutputStream( file ); if ( encoding != null ) writer = new OutputStreamWriter( out, encoding ); writer = new OutputStreamWriter( out ); IOUtil.close( writer );
/** * Get the contents of an <code>InputStream</code> as a String. The platform's default encoding is used for the * byte-to-char conversion. */ public static String toString( final InputStream input ) throws IOException { return toString( input, DEFAULT_BUFFER_SIZE ); }
try input1 = new FileInputStream( file1 ); input2 = new FileInputStream( file2 ); equals = IOUtil.contentEquals( input1, input2 ); input1.close(); input1 = null; input2.close(); input2 = null; IOUtil.close( input1 ); IOUtil.close( input2 );
FileInputStream instream = new FileInputStream( from ); FileOutputStream outstream = new FileOutputStream( to ); fileWriter = new OutputStreamWriter( outstream, encoding ); IOUtil.copy( reader, fileWriter ); fileWriter.close(); fileWriter = null; IOUtil.close( fileReader ); IOUtil.close( fileWriter );
try fis = new FileInputStream( source ); fos = new FileOutputStream( destination ); input = fis.getChannel(); output = fos.getChannel(); long size = input.size(); long pos = 0; fos.close(); fos = null; input.close(); input = null; fis.close(); fis = null; IOUtil.close( output ); IOUtil.close( fos ); IOUtil.close( input ); IOUtil.close( fis );
/** * @see org.apache.maven.plugin.eclipse.writers.EclipseWriter#write() */ public void write() throws MojoExecutionException { // create a .settings directory (if not existing) File settingsDir = new File( config.getEclipseProjectDirectory(), DIR_WTP_SETTINGS ); settingsDir.mkdirs(); Writer w; String packaging = config.getPackaging(); // Write out facet core xml try { w = new OutputStreamWriter( new FileOutputStream( new File( settingsDir, FILE_FACET_CORE_XML ) ), "UTF-8" ); } catch ( IOException ex ) { throw new MojoExecutionException( Messages.getString( "EclipsePlugin.erroropeningfile" ), ex ); //$NON-NLS-1$ } XMLWriter writer = new PrettyPrintXMLWriter( w, "UTF-8", null ); writeModuleTypeFacetCore( writer, packaging ); IOUtil.close( w ); }
try out = new FileOutputStream( fileName, true ); if ( encoding != null ) out.write( data.getBytes( encoding ) ); out.write( data.getBytes() ); out.close(); IOUtil.close( out );
reader = new InputStreamReader( new FileInputStream( file ), encoding ); reader = new InputStreamReader( new FileInputStream( file ) ); IOUtil.close( reader );
private void copyZipFileToDestDirUsingTempFile(File zipFile, File dest) throws IOException, MojoExecutionException { if (!dest.isDirectory()) { throw new IllegalArgumentException("destination must be a directory"); } InputStream muleZipInput = null; OutputStream tempOutput = null; try { muleZipInput = new FileInputStream(zipFile); File tempFile = new File(dest, zipFile.getName().replace(".zip", ".temp")); tempOutput = new FileOutputStream(tempFile); IOUtil.copy(muleZipInput, tempOutput); getLog().info(String.format("Copying %1s to %2s", zipFile.getAbsolutePath(), tempFile.getAbsolutePath())); File finalFile = new File(dest, zipFile.getName()); if (tempFile.renameTo(finalFile) == false) { throw new MojoExecutionException(String.format("Could not rename %1s to %2s", tempFile.getAbsolutePath(), finalFile.getAbsolutePath())); } } finally { IOUtil.close(muleZipInput); IOUtil.close(tempOutput); } }
private Manifest getManifest( File manifestFile ) throws ArchiverException { InputStream in = null; try { in = new FileInputStream( manifestFile ); final Manifest mf = getManifest( in ); in.close(); in = null; return mf; } catch ( IOException e ) { throw new ArchiverException( "Unable to read manifest file: " + manifestFile + " (" + e.getMessage() + ")", e ); } finally { IOUtil.close( in ); } }
private String checksum( File file, String type ) throws IOException, NoSuchAlgorithmException { MessageDigest md5 = MessageDigest.getInstance( type ); InputStream is = new FileInputStream( file ); byte[] buf = new byte[8192]; int i; while ( ( i = is.read( buf ) ) > 0 ) { md5.update( buf, 0, i ); } IOUtil.close( is ); return encode( md5.digest() ); }
public static Properties loadProperties( final InputStream is ) throws IOException { InputStream in = is; try { final Properties properties = new Properties(); // Make sure the properties stream is valid if ( in != null ) { properties.load( in ); in.close(); in = null; } return properties; } finally { IOUtil.close( in ); } }
public void calculate( File file ) throws MojoExecutionException { FileInputStream fis = null; BufferedInputStream bis = null; try { fis = new FileInputStream( file ); calculate( fis ); } catch ( IOException e ) { throw new MojoExecutionException( "Failed to calculate digest checksum for " + file, e ); } finally { IOUtil.close( bis ); IOUtil.close( fis ); } }
private void writePlugin( File addinPath ) throws MojoExecutionException { OutputStreamWriter writer = null; if ( !addinPath.exists() ) { addinPath.mkdirs(); } try { String addin = IOUtil.toString( VsInstallerMojo.class.getResourceAsStream( "/template/NPanday.VisualStudio.AddIn" ) ); File outputFile = new File( addinPath, "NPanday.VisualStudio.AddIn" ); writer = new OutputStreamWriter( new FileOutputStream( outputFile ), "Unicode" ); writer.write( addin.replaceAll( "\\$\\{installationLocation\\}", installationLocation.getAbsolutePath().replaceAll( "\\\\", "\\\\\\\\" ) ) ); } catch ( IOException e ) { throw new MojoExecutionException( "Unable to write to Visual Studio AddIns directory: " + e.getMessage() ); } finally { IOUtil.close( writer ); } }
private static void storeProperties( Properties props, File f ) throws MojoExecutionException { OutputStream os = null; try { os = new FileOutputStream( f ); props.store( os, null ); } catch ( IOException ioe ) { throw new MojoExecutionException( Messages.getString( "EclipsePlugin.cantwritetofile", //$NON-NLS-1$ f.getAbsolutePath() ) ); } finally { IOUtil.close( os ); } } }
public void write(final File file, final Map<String, Object> options, final Model model) throws IOException { assert file != null; assert model != null; OutputStream out = new BufferedOutputStream(new FileOutputStream(file)); try { write(out, options, model); out.flush(); } finally { IOUtil.close(out); } }
try final OutputStream out = new FileOutputStream( entryFile ); try IOUtil.copy( in, out );
if (!contentDirectory.exists()) getLog().warn(getType() + " directory is empty! " + contentDirectory); return; transformer.setErrorListener(error -> getLog().error(error)); int instrumentedCount = 0; ClassLoader classLoader = createClassLoader(); getLog().error("Error instrumenting " + resource.getName(), e); getLog().debug("instrumented: " + resource.getName()); IOUtil.copy(bytes, new FileOutputStream(new File(getOutputDirectory(), resource.getName()))); instrumentedCount++; throw new MojoExecutionException("Error assembling instrumenting", e);