.set(CREATE_PARENTS, lenient);
@Override public boolean setTime( final FsEntryName name, final BitField<Access> types, final long value, BitField<FsOutputOption> options) throws IOException { final Path file = target.resolve(name.getPath()); final FileTime time = FileTime.fromMillis(value); getBasicFileAttributeView(file).setTimes( types.get(WRITE) ? time : null, types.get(READ) ? time : null, types.get(CREATE) ? time : null); return types.clear(WRITE).clear(READ).clear(CREATE).isEmpty(); }
/** * @deprecated As of TrueZIP 7.5, replaced by {@link TVFS#sync(BitField)}. * @see <a href="http://java.net/jira/browse/TRUEZIP-236">#TRUEZIP-236</a> */ @Deprecated public static void umount( boolean waitCloseInput, boolean forceCloseInput, boolean waitCloseOutput, boolean forceCloseOutput) throws FsSyncException { TVFS.sync(BitField .of(CLEAR_CACHE) .set(WAIT_CLOSE_INPUT, waitCloseInput) .set(FORCE_CLOSE_INPUT, forceCloseInput) .set(WAIT_CLOSE_OUTPUT, waitCloseOutput) .set(FORCE_CLOSE_OUTPUT, forceCloseOutput)); }
/** * Sets the input preferences. * These preferences are usually not cached, so changing them should take * effect immediately. * * @param preferences the input preferences. * @throws IllegalArgumentException if an option is present in * {@code preferences} which is not present in * {@link FsInputOptions#INPUT_PREFERENCES_MASK}. * @since TrueZIP 7.3 */ public void setInputPreferences(final BitField<FsInputOption> preferences) { final BitField<FsInputOption> illegal = preferences .and(INPUT_PREFERENCES_COMPLEMENT_MASK); if (!illegal.isEmpty()) throw new IllegalArgumentException(illegal + " (illegal input preference(s))"); this.inputPreferences = preferences; }
/** * Sets the output preferences. * These preferences are usually not cached, so changing them should take * effect immediately. * * @param preferences the output preferences. * @throws IllegalArgumentException if an option is present in * {@code preferences} which is not present in * {@link FsOutputOptions#OUTPUT_PREFERENCES_MASK} or if both * {@link FsOutputOption#STORE} and * {@link FsOutputOption#COMPRESS} have been set. * @since TrueZIP 7.3 */ public void setOutputPreferences(final BitField<FsOutputOption> preferences) { final BitField<FsOutputOption> illegal = preferences .and(OUTPUT_PREFERENCES_COMPLEMENT_MASK); if (!illegal.isEmpty()) throw new IllegalArgumentException(illegal + " (illegal output preference(s))"); if (preferences.get(STORE) && preferences.get(COMPRESS)) throw new IllegalArgumentException(preferences + " (either STORE or COMPRESS may be set, but not both)"); this.outputPreferences = preferences; }
throw new FileSystemException(src.toString(), dst.toString(), "Source and destination are the same file!"); boolean preserve = false; BitField<FsOutputOption> o = dst.getOutputPreferences().set(EXCLUSIVE); for (final CopyOption option : options) { if (!(option instanceof StandardCopyOption)) switch ((StandardCopyOption) option) { case REPLACE_EXISTING: o = o.clear(EXCLUSIVE); break; case COPY_ATTRIBUTES: if (!srcEntry.isType(FILE)) throw new FileSystemException(src.toString(), null, "Expected type FILE, but is " + BitField.copyOf(srcEntry.getTypes()) + "!"); if (null != dstEntry) { if (o.get(EXCLUSIVE)) throw new FileAlreadyExistsException(dst.toString()); if (dstEntry.isType(DIRECTORY)) {
/** * Sets {@link FsOutputOption#STORE} in {@code options} before * forwarding the call to {@code controller}. */ @Override public final OptionOutputSocket getOutputSocket( final FsController<?> controller, final FsEntryName name, BitField<FsOutputOption> options, final @CheckForNull Entry template) { // Leave FsOutputOption.COMPRESS untouched - the driver shall be given // opportunity to apply its own preferences to sort out such a conflict. options = options.set(STORE); // The RAES file format cannot support GROWing. options = options.clear(GROW); return new OptionOutputSocket( controller.getOutputSocket(name, options, template), options); }
/** * Returns the value of the property {@code lenient}. * * @return The value of the property {@code lenient}. * @see #setLenient(boolean) */ public boolean isLenient() { return this.outputPreferences.get(CREATE_PARENTS); }
SeekableByteChannel newByteChannel( final TPath path, final Set<? extends OpenOption> options, final FileAttribute<?>... attrs) throws IOException { final FsEntryName name = path.getEntryName(); final FsController<?> controller = getController(); if (options.isEmpty() || options.contains(StandardOpenOption.READ)) { final BitField<FsInputOption> o = path.mapInput(options).set(FsInputOption.CACHE); return controller .getInputSocket(name, o) .newSeekableByteChannel(); } else { final BitField<FsOutputOption> o = path.mapOutput(options).set(FsOutputOption.CACHE); try { return controller .getOutputSocket(name, o, null) .newSeekableByteChannel(); } catch (final IOException ex) { if (o.get(EXCLUSIVE) && null != controller.getEntry(name)) throw (IOException) new FileAlreadyExistsException(path.toString()) .initCause(ex); throw ex; } } }
BitField<FsOutputOption> getOutputPreferences() { final BitField<FsOutputOption> prefs = TConfig .get() .getOutputPreferences(); return null != getMountPoint().getParent() ? prefs : prefs.clear(CREATE_PARENTS); }
@Test public void testOr() { BitField<Dummy> bits = BitField.noneOf(Dummy.class); assertThat(bits.cardinality(), is(0)); assertThat(bits.and(BitField.noneOf(Dummy.class)), sameInstance(bits)); bits = bits.or(BitField.allOf(Dummy.class)); assertThat(bits.cardinality(), is(3)); }
try { assertTrue(c.isLenient()); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertTrue(c.getInputPreferences().isEmpty()); assertTrue(c.getOutputPreferences().isEmpty()); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); c.setInputPreferences(BitField.of(FsInputOption.CACHE)); assertThat(c.getInputPreferences(), is(BitField.of(FsInputOption.CACHE))); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); c.setOutputPreferences(BitField.of(CACHE)); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CACHE))); c.setOutputPreferences(BitField.of(CREATE_PARENTS)); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS)));
BitField<FsOutputOption> mapOutput(final Set<? extends OpenOption> options) { final EnumSet<FsOutputOption> set = EnumSet.noneOf(FsOutputOption.class); for (final OpenOption option : options) { if (!(option instanceof StandardOpenOption)) throw new UnsupportedOperationException(option.toString()); switch ((StandardOpenOption) option) { case READ: throw new IllegalArgumentException(option.toString()); case WRITE: case TRUNCATE_EXISTING: case CREATE: break; case APPEND: set.add(APPEND); break; case CREATE_NEW: set.add(EXCLUSIVE); break; default: throw new UnsupportedOperationException(option.toString()); } } final BitField<FsOutputOption> prefs = getOutputPreferences(); return set.isEmpty() ? prefs : prefs.or(BitField.copyOf(set)); }
.getController( srcPath.getMountPoint(), driver) .getInputSocket( srcPath.getEntryName(), BitField.noneOf(FsInputOption.class)); .getController( dstPath.getMountPoint(), driver) .getOutputSocket( dstPath.getEntryName(), BitField.of(FsOutputOption.CREATE_PARENTS, FsOutputOption.EXCLUSIVE), srcSocket.getLocalTarget());
{ ENCODING_MASK, "_-!.~'()*", "_-!.~'()*" }, // mark { ENCODING_MASK, "@", "@" }, { BitField.of(ANY, PATH), ":", "%3A" }, { BitField.of(AUTHORITY, ABSOLUTE_PATH, QUERY, FRAGMENT), ":", ":" }, { BitField.of(ANY, AUTHORITY), "/", "%2F" }, { BitField.of(ABSOLUTE_PATH, PATH, QUERY, FRAGMENT), "/", "/" }, { BitField.of(ANY, AUTHORITY, ABSOLUTE_PATH, PATH), "?", "%3F" }, { BitField.of(QUERY, FRAGMENT), "?", "?" }, { ENCODING_MASK, "#", "%23" }, { ENCODING_MASK, "%", "%25" }, // percent
}) { final BitField<Dummy> original = BitField.copyOf(Arrays.asList(params));
@Test public void testSetTwo() { BitField<Dummy> bits = BitField.of(ONE, TWO); assertFalse(bits.isEmpty()); assertThat(bits.cardinality(), is(2)); assertTrue(bits.get(ONE)); assertTrue(bits.is(ONE)); assertTrue(bits.get(TWO)); assertTrue(bits.is(TWO)); assertThat(BitField.copyOf(bits.toEnumSet()), equalTo(bits)); }