blob: 8e8115af375844faa60181814dd8062cc321c0b5 (
plain)
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
|
/* -*- tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package org.libreoffice.storage.local;
import java.io.File;
import java.io.FileFilter;
import java.net.URI;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.libreoffice.storage.IFile;
/**
* Implementation of IFile for the local file system.
*/
public class LocalFile implements IFile {
private File file;
public LocalFile(File file) {
this.file = file;
}
public LocalFile(URI uri) {
this.file = new File(uri);
}
public URI getUri() {
return file.toURI();
}
public String getName() {
return file.getName();
}
@Override
public boolean isDirectory() {
return file.isDirectory();
}
@Override
public long getSize() {
return file.length();
}
@Override
public Date getLastModified() {
return new Date(file.lastModified());
}
@Override
public List<IFile> listFiles() {
List<IFile> children = new ArrayList<IFile>();
for (File child : file.listFiles()) {
children.add(new LocalFile(child));
}
return children;
}
@Override
public List<IFile> listFiles(FileFilter filter) {
List<IFile> children = new ArrayList<IFile>();
for (File child : file.listFiles(filter)) {
children.add(new LocalFile(child));
}
return children;
}
@Override
public IFile getParent() {
return new LocalFile(file.getParentFile());
}
@Override
public File getDocument() {
return file;
}
@Override
public boolean equals(Object object) {
if (this == object)
return true;
if (!(object instanceof LocalFile))
return false;
LocalFile file = (LocalFile) object;
return file.getUri().equals(getUri());
}
}
|