Lab3 #2
9
Lab3/src/main/java/org/lumijiez/base/ArbitraryFile.java
Normal file
9
Lab3/src/main/java/org/lumijiez/base/ArbitraryFile.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package org.lumijiez.base;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class ArbitraryFile extends Document{
|
||||||
|
public ArbitraryFile(Path path) {
|
||||||
|
super(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Lab3/src/main/java/org/lumijiez/base/CodeFile.java
Normal file
9
Lab3/src/main/java/org/lumijiez/base/CodeFile.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package org.lumijiez.base;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class CodeFile extends Document{
|
||||||
|
public CodeFile(Path path) {
|
||||||
|
super(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,31 +3,57 @@ package org.lumijiez.base;
|
|||||||
import org.lumijiez.enums.FileType;
|
import org.lumijiez.enums.FileType;
|
||||||
import org.lumijiez.interfaces.IDocument;
|
import org.lumijiez.interfaces.IDocument;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.attribute.BasicFileAttributes;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public class Document implements IDocument {
|
public class Document extends File implements IDocument {
|
||||||
private String fullFilename = "";
|
private String extension;
|
||||||
private FileType fileType;
|
private FileType fileType;
|
||||||
private Date createdAt;
|
|
||||||
private Date modifiedAt;
|
|
||||||
|
|
||||||
@Override
|
public Document(Path path) {
|
||||||
public String getFilename() {
|
super(path.toString());
|
||||||
return null;
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
int lastDotIndex = getName().lastIndexOf('.');
|
||||||
|
extension = (lastDotIndex > 0) ? getName().substring(lastDotIndex + 1) : "";
|
||||||
|
fileType = FileType.getFileType(extension);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getExtension() {
|
public String getExtension() {
|
||||||
return null;
|
return extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getCreatedTime() {
|
public Date getCreatedTime() {
|
||||||
|
try {
|
||||||
|
BasicFileAttributes fileAttributes = Files.readAttributes(Path.of(this.getPath()), BasicFileAttributes.class);
|
||||||
|
return new Date(fileAttributes.creationTime().toMillis());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Date getModificationTime() {
|
public Date getModificationTime() {
|
||||||
|
try {
|
||||||
|
BasicFileAttributes fileAttributes = Files.readAttributes(Path.of(this.getPath()), BasicFileAttributes.class);
|
||||||
|
return new Date(fileAttributes.lastAccessTime().toMillis());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public FileType getFileType() {
|
||||||
|
return fileType;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
9
Lab3/src/main/java/org/lumijiez/base/ImageFile.java
Normal file
9
Lab3/src/main/java/org/lumijiez/base/ImageFile.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package org.lumijiez.base;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class ImageFile extends Document{
|
||||||
|
public ImageFile(Path path) {
|
||||||
|
super(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
9
Lab3/src/main/java/org/lumijiez/base/TextFile.java
Normal file
9
Lab3/src/main/java/org/lumijiez/base/TextFile.java
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
package org.lumijiez.base;
|
||||||
|
|
||||||
|
import java.nio.file.Path;
|
||||||
|
|
||||||
|
public class TextFile extends Document {
|
||||||
|
public TextFile(Path path) {
|
||||||
|
super(path);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,8 +4,22 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public enum FileType {
|
public enum FileType {
|
||||||
IMAGE, PLAINTEXT, FILE, CODE;
|
IMAGE("Image"), PLAINTEXT("Plaintext"), FILE("File"), CODE("Code"), NONE("None");
|
||||||
public List<String> typeExtensions;
|
public List<String> typeExtensions;
|
||||||
|
public final String typeName;
|
||||||
|
|
||||||
|
FileType(String typeName) {
|
||||||
|
this.typeName = typeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static FileType getFileType(String extension) {
|
||||||
|
for (FileType fileType : values()) {
|
||||||
|
if (fileType.typeExtensions.contains(extension.toLowerCase())) {
|
||||||
|
return fileType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NONE;
|
||||||
|
}
|
||||||
|
|
||||||
static {
|
static {
|
||||||
IMAGE.typeExtensions = new ArrayList<>(List.of("jpg", "png"));
|
IMAGE.typeExtensions = new ArrayList<>(List.of("jpg", "png"));
|
||||||
|
|||||||
@@ -1,10 +1,12 @@
|
|||||||
package org.lumijiez.interfaces;
|
package org.lumijiez.interfaces;
|
||||||
|
|
||||||
|
import org.lumijiez.enums.FileType;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
public interface IDocument {
|
public interface IDocument {
|
||||||
public String getFilename();
|
|
||||||
public String getExtension();
|
public String getExtension();
|
||||||
public Date getCreatedTime();
|
public Date getCreatedTime();
|
||||||
public Date getModificationTime();
|
public Date getModificationTime();
|
||||||
|
public FileType getFileType();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user