public static void copyFileWithException( final File _source, final File _dest ) throws IOException{ copyFile( new FileInputStream( _source ), new FileOutputStream( _dest ) ); }
public static void copyFileOrDirectory( File from_file_or_dir, File to_parent_dir ) throws IOException { if ( !from_file_or_dir.exists()){ throw( new IOException( "File '" + from_file_or_dir.toString() + "' doesn't exist" )); } if ( !to_parent_dir.exists()){ throw( new IOException( "File '" + to_parent_dir.toString() + "' doesn't exist" )); } if ( !to_parent_dir.isDirectory()){ throw( new IOException( "File '" + to_parent_dir.toString() + "' is not a directory" )); } if ( from_file_or_dir.isDirectory()){ File[] files = from_file_or_dir.listFiles(); File new_parent = new File( to_parent_dir, from_file_or_dir.getName()); FileUtil.mkdirs(new_parent); for (int i=0;i<files.length;i++){ File from_file = files[i]; copyFileOrDirectory( from_file, new_parent ); } }else{ File target = new File( to_parent_dir, from_file_or_dir.getName()); if ( !copyFile( from_file_or_dir, target )){ throw( new IOException( "File copy from " + from_file_or_dir + " to " + target + " failed" )); } } }
public static boolean copyFile( final File _source, final OutputStream _dest, boolean closeInputStream ) { try { copyFile( new FileInputStream( _source ), _dest, closeInputStream ); return true; } catch( Throwable e ) { Debug.printStackTrace( e ); return false; } }
public static void importDownloadState( File source_dir, byte[] download_hash ) throws DownloadManagerException { String hash_str = ByteFormatter.encodeString( download_hash ); String state_file = hash_str + ".dat"; File target_state_file = new File( ACTIVE_DIR, state_file ); File source_state_file = new File( source_dir, state_file ); if ( !source_state_file.exists()){ throw( new DownloadManagerException( "Source state file missing: " + source_state_file )); } if ( target_state_file.exists()){ target_state_file.delete(); //throw( new DownloadManagerException( "Target state file already exists: " + target_state_file )); } if ( !FileUtil.copyFile( source_state_file, target_state_file )){ throw( new DownloadManagerException( "Failed to copy state file: " + source_state_file + " -> " + target_state_file )); } File source_state_dir = new File( source_dir, hash_str ); if ( source_state_dir.exists()){ try{ FileUtil.copyFileOrDirectory( source_state_dir, ACTIVE_DIR ); }catch( Throwable e ){ target_state_file.delete(); throw( new DownloadManagerException( "Failed to copy state dir: " + source_dir + " -> " + ACTIVE_DIR, e )); } } }
/** * Backup the given file to filename.bak, removing the old .bak file if necessary. * If _make_copy is true, the original file will copied to backup, rather than moved. * @param _file file to backup * @param _make_copy copy instead of move */ public static void backupFile( final File _file, final boolean _make_copy ) { if ( _file.length() > 0L ) { File bakfile = new File( _file.getAbsolutePath() + ".bak" ); if ( bakfile.exists() ) bakfile.delete(); if ( _make_copy ) { copyFile( _file, bakfile ); } else { _file.renameTo( bakfile ); } } }
@Override public boolean exportState( File target_dir ) { try{ this_mon.enter(); save( true ); byte[] hash = torrent.getHash(); String hash_str = ByteFormatter.encodeString( hash ); String state_file = hash_str + ".dat"; File existing_state_file = new File( ACTIVE_DIR, state_file ); File target_state_file = new File( target_dir, state_file ); if ( !FileUtil.copyFile( existing_state_file, target_state_file )){ throw( new IOException( "Failed to copy state file" )); } File existing_state_dir = new File( ACTIVE_DIR, hash_str ); if ( existing_state_dir.exists()){ FileUtil.copyFileOrDirectory( existing_state_dir, target_dir ); } return( true ); }catch( Throwable e ){ Debug.out( e ); return( false ); }finally{ this_mon.exit(); } }
public static void copyFile( final InputStream _source, final File _dest, boolean _close_input_stream ) throws IOException { FileOutputStream dest = null; boolean close_input = _close_input_stream; try{ dest = new FileOutputStream(_dest); close_input = false; copyFile( _source, dest, close_input ); }finally{ try{ if( close_input ){ _source.close(); } }catch( IOException e ){ } if ( dest != null ){ dest.close(); } } }
copyFile( _source, dest, true );
public static void copyFile( InputStream is, OutputStream os, boolean closeInputStream ) throws IOException { try{ if ( !(is instanceof BufferedInputStream )){ is = new BufferedInputStream(is,128*1024); } byte[] buffer = new byte[128*1024]; while(true){ int len = is.read(buffer); if ( len == -1 ){ break; } os.write( buffer, 0, len ); } }finally{ try{ if(closeInputStream){ is.close(); } }catch( IOException e ){ } os.close(); } }
@Override public void addResource( String resource_name, InputStream is, boolean closeInputStream) throws UpdateException { try{ File target_file = new File(install_dir, resource_name ); FileUtil.copyFile( is, new FileOutputStream( target_file ),closeInputStream); }catch( Throwable e ){ throw( new UpdateException( "UpdateInstaller: resource addition fails", e )); } }
@Override public void handleEvent(Event arg0) { //In case we enable the XP Style if (enableXPStyle.getSelection()) { try { File fDest = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest"); File fOrigin = new File("javaw.exe.manifest"); if (!fDest.exists() && fOrigin.exists()) { FileUtil.copyFile(fOrigin, fDest); } } catch (Exception e) { Debug.printStackTrace(e); } } else { try { File fDest = new File(System.getProperty("java.home") + "\\bin\\javaw.exe.manifest"); fDest.delete(); } catch (Exception e) { Debug.printStackTrace(e); } } } });
public void signJarFile( File file, OutputStream os ) throws IOException { signJarFile( file ); FileInputStream fis = null; try{ fis = new FileInputStream( file ); FileUtil.copyFile( file, os, false ); }finally{ try{ if (fis != null) {fis.close();} }catch( Throwable e ){ Debug.printStackTrace(e); } } }
copyFile( new FileInputStream( _source ), new FileOutputStream( _dest ) ); return true;
private void initEmptyTrustStore() { try{ File target = new File( truststore_name ); if ( target.exists() && target.length() > 2*1024 ){ // doesn't look very empty, bail! return; } KeyStore keystore = getTrustStore(); if ( keystore.size() == 0 ){ File cacerts = new File( new File( new File( System.getProperty( "java.home" ), "lib" ), "security" ), "cacerts" ); if ( cacerts.exists()){ FileUtil.copyFile( cacerts, target ); try{ getTrustStore(); }catch( Throwable e ){ target.delete(); ensureStoreExists( truststore_name ); } } } }catch( Throwable e ){ } }
if ( !FileUtil.copyFile( cacerts, target )){
if (!FileUtil.copyFile(f, fDest)) { throw new IOException("File copy failed");
private File extractFromVuzeFile( File file ) throws PluginException { VuzeFile vf = VuzeFileHandler.getSingleton().loadVuzeFile(file); VuzeFileComponent[] comps = vf.getComponents(); for (int j=0;j<comps.length;j++){ VuzeFileComponent comp = comps[j]; if ( comp.getType() == VuzeFileComponent.COMP_TYPE_PLUGIN ){ try{ Map content = comp.getContent(); String id = new String((byte[])content.get( "id" ), "UTF-8" ); String version = new String((byte[])content.get( "version" ), "UTF-8" ); String suffix = ((Long)content.get( "is_jar" )).longValue()==1?"jar":"zip"; byte[] plugin_file = (byte[])content.get( "file" ); File temp_dir = AETemporaryFileHandler.createTempDir(); File temp_file = new File( temp_dir, id + "_" + version + "." + suffix ); FileUtil.copyFile( new ByteArrayInputStream( plugin_file ), temp_file ); return( temp_file ); }catch( Throwable e ){ throw( new PluginException( "Not a valid Vuze file", e )); } } } return( file ); }
FileUtil.copyFile( new ByteArrayInputStream( plugin_file ), temp_file );
if ( download_dir != null && actual_target_file.exists()){ FileUtil.copyFile( actual_target_file, target_file );
FileUtil.copyFile(data, FileUtil.getUserFile("ipfilter.dl")); AEThread thread = new AEThread("reload ipfilters", true) { @Override