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

de.schlichtherle.io.archive.spi.RfsEntry Maven / Gradle / Ivy

Go to download

TrueZIP is a Java based Virtual File System (VFS) to enable transparent, multi-threaded read/write access to archive files (ZIP, TAR etc.) as if they were directories. Archive files may be arbitrarily nested and the nesting level is only limited by heap and file system size.

The newest version!
/*
 * Copyright (C) 2006-2010 Schlichtherle IT Services
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package de.schlichtherle.io.archive.spi;

import de.schlichtherle.io.ArchiveEntryMetaData;

import java.io.File;

import javax.swing.Icon;

/**
 * A utility class which adapts a {@link File} instance to an
 * {@link ArchiveEntry} (RFS means Real File System).
 *
 * @author Christian Schlichtherle
 * @version $Id: RfsEntry.java,v 1.4 2010/08/20 13:09:48 christian_schlichtherle Exp $
 * @since TrueZIP 6.5
 */
public class RfsEntry implements ArchiveEntry {
    private final String entryName;
    private final File file;

    /**
     * Constructs a new {@code RfsEntry}.
     * This constructor uses the file's path to build a valid entry name.
     * 
     * @param file A valid {@code File} instance.
     * @throws NullPointerException If {@code file} is {@code null}.
     */
    public RfsEntry(final File file) {
        this(file, getName(file));
    }

    /**
     * Constructs a new {@code RfsEntry}.
     * 
     * @param file A valid {@code File} instance.
     * @param entryName A valid archive entry name.
     * @see Requirements for Archive Entry Names
     * @throws NullPointerException If any parameter is {@code null}.
     */
    public RfsEntry(final File file, final String entryName) {
        if (entryName == null || file == null)
            throw new NullPointerException();
        this.entryName = entryName;
        this.file = file;
    }

    /** Returns the adapted file. */
    public File getFile() {
        return file;
    }

    private static String getName(File file) {
        String entryName = file.getPath().replace(
                File.separatorChar, SEPARATOR_CHAR);
        if (file.isDirectory())
            return entryName + SEPARATOR_CHAR;
        return entryName;
    }

    /** Returns the name provided to the constructor. */
    public String getName() {
        return entryName;
    }

    /** Returns whether the file is a directory or not. */
    public boolean isDirectory() {
        return file.isDirectory();
    }

    /** Returns the file size. */
    public long getSize() {
        return file.length();
    }

    /** Returns the file's last modification time. */
    public long getTime() {
        return file.lastModified();
    }

    /** Sets the file's last modification time. */
    public void setTime(long time) {
        file.setLastModified(time);
    }

    /** Returns {@code null}. */
    public Icon getOpenIcon() {
        return null;
    }

    /** Returns {@code null}. */
    public Icon getClosedIcon() {
        return null;
    }

    /** Returns {@code null}. */
    public ArchiveEntryMetaData getMetaData() {
        return null;
    }

    /** A no-op: Does nothing. */
    public void setMetaData(ArchiveEntryMetaData metaData) {
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy