/** * 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; }
@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(); }
@Test public void testClearOne() { BitField<Dummy> bits = BitField.of(ONE).clear(ONE); assertTrue(bits.isEmpty()); assertThat(bits.cardinality(), is(0)); assertFalse(bits.get(ONE)); assertFalse(bits.is(ONE)); assertThat(BitField.copyOf(bits.toEnumSet()), equalTo(bits)); }
@Test public void testSetOne() { BitField<Dummy> bits = BitField.noneOf(Dummy.class).set(ONE); assertFalse(bits.isEmpty()); assertThat(bits.cardinality(), is(1)); assertTrue(bits.get(ONE)); assertTrue(bits.is(ONE)); assertThat(BitField.copyOf(bits.toEnumSet()), equalTo(bits)); }
@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)); }
@Test public void defaults() { final TConfig c = TConfig.get(); assertThat(TConfig.get(), sameInstance(c)); final TArchiveDetector detector = c.getArchiveDetector(); assertThat(detector, sameInstance(TArchiveDetector.ALL)); assertThat(c.getArchiveDetector(), sameInstance(detector)); final boolean lenient = c.isLenient(); assertThat(lenient, is(true)); assertThat(c.isLenient(), is(lenient)); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); }
@Test public void testClearTwo() { BitField<Dummy> bits = BitField.of(ONE, TWO).clear(ONE).clear(TWO); assertTrue(bits.isEmpty()); assertThat(bits.cardinality(), is(0)); assertFalse(bits.get(ONE)); assertFalse(bits.is(ONE)); assertFalse(bits.get(TWO)); assertFalse(bits.is(TWO)); assertThat(BitField.copyOf(bits.toEnumSet()), equalTo(bits)); }
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))); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CACHE))); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(CREATE_PARENTS))); assertTrue(c.getInputPreferences().isEmpty()); assertThat(c.getOutputPreferences(), is(BitField.of(STORE)));