/** * Copies a single source file to a destination file. * The name of this method is inspired by the Unix command line utility * {@code cp}. * * @param preserve if an elementary cp operation shall cp as much * properties of the source file to the destination file, too. * Currently, only the last modification time is preserved. * Note that this property set may get extended over time. * @param src the source file. * This file system entity needs to exist. * @param dst the destination file. * This file systeme entity may or may not exist. * If it does, its contents are overwritten. * @throws IOException if the source path contains the destination path * or an elementary operation fails for any reason. */ static void cp(final boolean preserve, final File src, final File dst) throws IOException { checkContains(src, dst); cp0(preserve, src, dst); }
/** * Equivalent to {@link #cp(File, File) cp(this, dst)}. * * @param dst the destination file. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @return {@code this} * @throws IOException if any I/O error occurs. */ public TFile cp(File dst) throws IOException { TBIO.cp(false, this, dst); return this; }
/** * Equivalent to {@link #cp_r(File, File, TArchiveDetector, TArchiveDetector) cp_r(this, dst, getArchiveDetector(), getArchiveDetector())}. * * @param dst the destination file or directory tree. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @return {@code this} * @throws IOException if any I/O error occurs. * @see <a href="#bulkIOMethods">Bulk I/O Methods</a> * @see <a href="#traversal">Traversing Directory Trees</a> */ public TFile cp_r(File dst) throws IOException { TBIO.cp_r(false, this, dst, detector, detector); return this; }
final TArchiveDetector dstDetector) throws IOException { checkContains(src, dst); cp_r0(preserve, src, dst, srcDetector, dstDetector);
/** * Moves the source file or directory tree to the destination file or * directory tree by performing a recursive cp-then-delete operation. * Hence, this file system operation works even with archive files or * entries within archive files, but is <em>not</em> atomic. * * @param src the source directory tree or file. * This file system entity needs to exist. * @param dst the destination directory tree or file. * This file systeme entity may or may not exist. * If it does, its contents are overwritten. * @param detector the object used to detect any archive files in the * source and destination paths. * @throws IOException if the source path contains the destination path * or an elementary operation fails for any reason. */ static void mv(final File src, final File dst, final TArchiveDetector detector) throws IOException { checkContains(src, dst); if (dst.exists()) throw new IOException(dst + " (destination exists already)"); mv0(src, dst, detector); }
/** Unchecked parameters version. */ private static void cp0(final boolean preserve, final File src, final File dst) throws IOException { final TConfig config = TConfig.get(); final InputSocket<?> input = getInputSocket(src, config.getInputPreferences()); final OutputSocket<?> output = getOutputSocket(dst, config.getOutputPreferences(), preserve ? input.getLocalTarget() : null); IOSocket.copy(input, output); }
.get() .getFsManager() .getController( path.getMountPoint(), getDetector(dst)) .getOutputSocket( path.getEntryName(), options.clear(CREATE_PARENTS),
@CreatesObligation private static InputStream newInputStream(final File src) throws FileNotFoundException { final InputSocket<?> input = TBIO.getInputSocket(src, TConfig.get().getInputPreferences()); try { return input.newInputStream(); } catch (FileNotFoundException ex) { throw ex; } catch (IOException ex) { throw (FileNotFoundException) new FileNotFoundException( src.toString()).initCause(ex); } } }
@CreatesObligation private static OutputStream newOutputStream(final File dst, final boolean append) throws FileNotFoundException { final OutputSocket<?> output = TBIO.getOutputSocket(dst, TConfig.get().getOutputPreferences().set(APPEND, append), null); try { return output.newOutputStream(); } catch (FileNotFoundException ex) { throw ex; } catch (IOException ex) { throw (FileNotFoundException) new FileNotFoundException( dst.toString()).initCause(ex); } } }
throw new IOException(src + " (cannot rename to " + dst + ")"); TBIO.mv(src, dst, detector);
/** * Returns an input socket for the given file. * * @param src the file to read. * @param options the options for accessing the file. * @return An input socket for the given file. */ @SuppressWarnings("deprecation") static InputSocket<?> getInputSocket(final File src, final BitField<FsInputOption> options) { if (src instanceof TFile) { final TFile tsrc = (TFile) src; final TFile archive = tsrc.getInnerArchive(); if (null != archive) return archive .getController() .getInputSocket(tsrc.getInnerFsEntryName(), options); } final FsPath path = new FsPath(src); return TConfig .get() .getFsManager() .getController( path.getMountPoint(), getDetector(src)) .getInputSocket(path.getEntryName(), options); }
/** * Equivalent to {@link #cp_rp(File, File, TArchiveDetector, TArchiveDetector) cp_rp(this, dst, getArchiveDetector(), getArchiveDetector())}. * * @param dst the destination file or directory tree. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @return {@code this} * @throws IOException if any I/O error occurs. * @see <a href="#bulkIOMethods">Bulk I/O Methods</a> * @see <a href="#traversal">Traversing Directory Trees</a> */ public TFile cp_rp(File dst) throws IOException { TBIO.cp_r(true, this, dst, detector, detector); return this; }
/** * Equivalent to {@link #cp_p(File, File) cp_p(this, dst)}. * * @param dst the destination file. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @return {@code this} * @throws IOException if any I/O error occurs. */ public TFile cp_p(File dst) throws IOException { TBIO.cp(true, this, dst); return this; }
/** * Equivalent to {@link #cp_rp(File, File, TArchiveDetector, TArchiveDetector) cp_rp(this, dst, detector, detector)}. * * @param src the source file or directory tree. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @param dst the destination file or directory tree. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @param detector the archive detector to use for detecting any * archive files <em>within</em> the source and destination * directory tree. * @throws IOException if any I/O error occurs. * @since TrueZIP 7.2 * @see <a href="#bulkIOMethods">Bulk I/O Methods</a> * @see <a href="#traversal">Traversing Directory Trees</a> */ @ExpertFeature( level=INTERMEDIATE, value=INJECTING_A_DIFFERENT_DETECTOR_FOR_THE_SAME_PATH_MAY_CORRUPT_DATA) public static void cp_rp(File src, File dst, TArchiveDetector detector) throws IOException { TBIO.cp_r(true, src, dst, detector, detector); }
TBIO.cp(true, src, dst);
/** * Equivalent to {@link #cp_r(File, File, TArchiveDetector, TArchiveDetector) cp_r(this, dst, detector, detector)}. * * @param src the source file or directory tree. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @param dst the destination file or directory tree. * Note that although this just needs to be a plain {@code File}, * archive files and entries are only supported for instances of * this class. * @param detector the archive detector to use for detecting any * archive files <em>within</em> the source and destination * directory tree. * @throws IOException if any I/O error occurs. * @since TrueZIP 7.2 * @see <a href="#bulkIOMethods">Bulk I/O Methods</a> * @see <a href="#traversal">Traversing Directory Trees</a> */ @ExpertFeature( level=INTERMEDIATE, value=INJECTING_A_DIFFERENT_DETECTOR_FOR_THE_SAME_PATH_MAY_CORRUPT_DATA) public static void cp_r(File src, File dst, TArchiveDetector detector) throws IOException { TBIO.cp_r(false, src, dst, detector, detector); }
TBIO.cp(false, src, dst);
TArchiveDetector dstDetector) throws IOException { TBIO.cp_r(true, src, dst, srcDetector, dstDetector);