-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFileWrapper.java
More file actions
55 lines (44 loc) · 1.22 KB
/
Copy pathFileWrapper.java
File metadata and controls
55 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package Mp3File;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.concurrent.TimeUnit;
public class FileWrapper {
protected Path path;
protected long length;
protected long lastModified;
protected FileWrapper() {
}
public FileWrapper(String filename) throws IOException {
this.path = Paths.get(filename);
init();
}
public FileWrapper(File file) throws IOException {
if (file == null) throw new NullPointerException();
this.path = Paths.get(file.getPath());
init();
}
public FileWrapper(Path path) throws IOException {
if (path == null) throw new NullPointerException();
this.path = path;
init();
}
private void init() throws IOException {
if (!Files.exists(path)) throw new FileNotFoundException("File not found " + path);
if (!Files.isReadable(path)) throw new IOException("File not readable");
length = Files.size(path);
lastModified = Files.getLastModifiedTime(path).to(TimeUnit.MILLISECONDS);
}
public String getFilename() {
return path.toString();
}
public long getLength() {
return length;
}
public long getLastModified() {
return lastModified;
}
}