All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.java.truevfs.kernel.impl.ReadOnlyArchiveFileSystem Maven / Gradle / Ivy

/*
 * Copyright © 2005 - 2021 Schlichtherle IT Services.
 * All rights reserved. Use is subject to license terms.
 */
package net.java.truevfs.kernel.impl;

import net.java.truecommons.cio.Container;
import net.java.truecommons.cio.Entry;
import net.java.truecommons.shed.BitField;
import net.java.truevfs.kernel.spec.FsAccessOption;
import net.java.truevfs.kernel.spec.FsArchiveEntry;
import net.java.truevfs.kernel.spec.FsNodeName;
import net.java.truevfs.kernel.spec.FsReadOnlyFileSystemException;

import javax.annotation.concurrent.NotThreadSafe;
import java.io.IOException;
import java.util.Map;
import java.util.Optional;
import java.util.function.Supplier;

import static net.java.truecommons.cio.Entry.Access.READ;

/**
 * A read-only virtual file system for archive entries.
 * 

* All modifying methods throw a {@link net.java.truevfs.kernel.spec.FsReadOnlyFileSystemException}. * * @param The type of the archive entries. * @author Christian Schlichtherle */ @NotThreadSafe final class ReadOnlyArchiveFileSystem extends ArchiveFileSystem { private static final BitField READ_ONLY = BitField.of(READ); private final Supplier cause; ReadOnlyArchiveFileSystem( final ArchiveModel model, final Container archive, final Entry rootTemplate, final Supplier cause ) { super(model, archive, rootTemplate); this.cause = cause; } @Override void checkAccess( final BitField options, final FsNodeName name, final BitField types ) throws IOException { if (!types.isEmpty() && READ_ONLY != types) { throw newFsReadOnlyFileSystemException(); } super.checkAccess(options, name, types); } @Override void setReadOnly(BitField options, FsNodeName name) throws IOException { } @Override boolean setTime(BitField options, FsNodeName name, Map times) throws IOException { throw newFsReadOnlyFileSystemException(); } @Override boolean setTime(BitField options, FsNodeName name, BitField types, long value) throws IOException { throw newFsReadOnlyFileSystemException(); } @Override ArchiveFileSystem.Make make(BitField options, FsNodeName name, Entry.Type type, Optional template) throws IOException { throw newFsReadOnlyFileSystemException(); } @Override void unlink(BitField options, FsNodeName name) throws IOException { throw newFsReadOnlyFileSystemException(); } private FsReadOnlyFileSystemException newFsReadOnlyFileSystemException() { return new FsReadOnlyFileSystemException(getMountPoint(), cause.get()); } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy