de.schlichtherle.truezip.fs.archive.zip.ZipDriverEntry Maven / Gradle / Ivy
Show all versions of truezip-driver-zip Show documentation
/*
* Copyright (C) 2005-2013 Schlichtherle IT Services.
* All rights reserved. Use is subject to license terms.
*/
package de.schlichtherle.truezip.fs.archive.zip;
import static de.schlichtherle.truezip.entry.Entry.Access.WRITE;
import static de.schlichtherle.truezip.entry.Entry.Size.DATA;
import static de.schlichtherle.truezip.entry.Entry.Type.DIRECTORY;
import static de.schlichtherle.truezip.entry.Entry.Type.FILE;
import de.schlichtherle.truezip.fs.FsArchiveEntries;
import de.schlichtherle.truezip.fs.FsArchiveEntry;
import de.schlichtherle.truezip.zip.DateTimeConverter;
import de.schlichtherle.truezip.zip.ZipEntry;
/**
* ZIP archive entries apply the date/time conversion rules as defined by
* {@link DateTimeConverter#ZIP}.
*
* @see #getDateTimeConverter()
* @see ZipDriver
* @author Christian Schlichtherle
*/
public class ZipDriverEntry extends ZipEntry implements FsArchiveEntry {
public ZipDriverEntry(String name) {
super(name);
}
protected ZipDriverEntry(String name, ZipEntry template) {
super(name, template);
}
@Override
public Type getType() {
return isDirectory() ? DIRECTORY : FILE;
}
/**
* Returns a {@link DateTimeConverter} for the conversion of Java time
* to DOS date/time fields and vice versa.
*
* The implementation in the class {@link ZipDriverEntry} returns
* {@link DateTimeConverter#ZIP}.
*
* @return {@link DateTimeConverter#ZIP}
*/
@Override
protected DateTimeConverter getDateTimeConverter() {
return DateTimeConverter.ZIP;
}
@Override
public long getSize(final Size type) {
switch (type) {
case DATA:
return getSize();
case STORAGE:
return getCompressedSize();
default:
return FsArchiveEntry.UNKNOWN;
}
}
@Override
public boolean setSize(final Size type, final long size) {
if (DATA != type)
return false;
setSize(size);
return true;
}
@Override
public long getTime(Access type) {
if (WRITE != type)
return FsArchiveEntry.UNKNOWN;
long time = getTime();
return 0 <= time ? time : FsArchiveEntry.UNKNOWN;
}
@Override
public boolean setTime(Access type, long time) {
if (WRITE != type)
return false;
setTime(time);
return true;
}
/**
* Returns a string representation of this object for debugging and logging
* purposes.
*/
@Override
public String toString() {
return FsArchiveEntries.toString(this);
}
}