/** * 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); }
FileOutputSocket( final FileEntry entry, final BitField<FsOutputOption> options, final @CheckForNull Entry template) { assert null != entry; assert null != options; if (options.get(EXCLUSIVE) && options.get(APPEND)) throw new IllegalArgumentException(); this.entry = entry; this.options = options; this.template = template; }
FileOutputSocket( final FileEntry entry, final BitField<FsOutputOption> options, final @CheckForNull Entry template) { assert null != entry; assert null != options; if (options.get(EXCLUSIVE) && options.get(APPEND)) throw new IllegalArgumentException(); this.entry = entry; this.options = options; this.template = template; }
private Set<OpenOption> optionSet() { final Set<OpenOption> set = new HashSet<OpenOption>(INITIAL_CAPACITY); Collections.addAll(set, WRITE_STANDARD_OPEN_OPTION); if (options.get(APPEND)) { set.add(StandardOpenOption.APPEND); set.remove(StandardOpenOption.TRUNCATE_EXISTING); } if (options.get(EXCLUSIVE)) set.add(StandardOpenOption.CREATE_NEW); return set; }
/** * 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; }
private FileEntry begin() throws IOException { final FileEntry temp; final File entryFile = entry.getFile(); Boolean exists = null; if (options.get(EXCLUSIVE) && (exists = entryFile.exists())) throw new IOException(entryFile + " (file exists already)"); // this is obviously not atomic if (options.get(CACHE)) { // This is obviously NOT atomic. if (TRUE.equals(exists) || null == exists && (exists = entryFile.exists())) { if (!entryFile.canWrite()) throw new FileNotFoundException(entryFile + " (cannot write)"); } else { if (!entryFile.createNewFile()) throw new FileNotFoundException(entryFile + " (already exists)"); } temp = entry.createTempFile(); } else { temp = entry; } if (options.get(CREATE_PARENTS) && !TRUE.equals(exists)) { final File parentFile = entryFile.getParentFile(); if (null != parentFile) if (!parentFile.mkdirs() && !parentFile.isDirectory()) throw new IOException(parentFile + " (cannot create directories)"); } return temp; }
switch (type) { case FILE: if (options.get(EXCLUSIVE)) { if (!file.createNewFile()) throw new IOException(file + " (file exists already)");
@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(); }
final Path entryFile = entry.getPath(); Boolean exists = null; if (options.get(EXCLUSIVE) && (exists = exists(entryFile))) throw new FileAlreadyExistsException(entry.toString()); if (options.get(CACHE)) { temp = entry; if (options.get(CREATE_PARENTS) && !TRUE.equals(exists)) { final Path parentFile = entryFile.getParent(); if (null != parentFile) {
private void append(final FileEntry temp) throws IOException { if (temp != entry && options.get(APPEND) && exists(entry.getPath())) IOSocket.copy(entry.getInputSocket(), temp.getOutputSocket()); }
private void append(final FileEntry temp) throws IOException { if (temp != entry && options.get(APPEND) && entry.getFile().exists()) IOSocket.copy(entry.getInputSocket(), temp.getOutputSocket()); }
@CreatesObligation private OutputShop<ZipDriverEntry> newOutputShop0( final FsModel model, final OptionOutputSocket output, final @CheckForNull @WillNotClose ZipInputShop source) throws IOException { final BitField<FsOutputOption> options = output.getOptions(); if (null != source) source.setAppendee(options.get(GROW)); return newOutputShop(model, output, source); }
@Override public void mknod( final FsEntryName name, final Type type, final BitField<FsOutputOption> options, final @CheckForNull Entry template) throws IOException { final Path file = target.resolve(name.getPath()); switch (type) { case FILE: if (options.get(EXCLUSIVE)) createFile(file); else newOutputStream(file).close(); break; case DIRECTORY: createDirectory(file); break; default: throw new IOException(file + " (entry type not supported: " + type + ")"); } if (null != template) { getBasicFileAttributeView(file) .setTimes( toFileTime(template.getTime(WRITE)), toFileTime(template.getTime(READ)), toFileTime(template.getTime(CREATE))); } }
if (options.get(GROW)) options = options.set(APPEND).clear(CACHE); return new OptionOutputSocket(
@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)); }
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; } } }
@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)); }
@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)); }