mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
change in filesystem --but in j2me no classes as in SE
with zip.. git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@532 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
0833381640
commit
9dca37a60b
6 changed files with 134 additions and 27 deletions
|
@ -1,8 +1,8 @@
|
|||
<?xml version="1.0"?>
|
||||
<project name="FBReaderJ" default="package">
|
||||
<property name="project.dir" value="/home/geometer/src/projects/FBReaderJ" />
|
||||
<property name="project.dir" value="C:/Documents and Settings/465/workspace/FBReaderJ" />
|
||||
<taskdef resource="antenna.properties" classpath="${project.dir}/lib/antenna-bin-1.0.0.jar"/>
|
||||
<property name="wtk.home" value="/home/geometer/WTK2.5.2" />
|
||||
<property name="wtk.home" value="C:/WTK2.5.2" />
|
||||
<property name="wtk.cldc.version" value="1.1" />
|
||||
<property name="wtk.midp.version" value="2.0" />
|
||||
<property name="wtk.optionalpda.enabled" value="true" />
|
||||
|
|
|
@ -34,7 +34,6 @@ public abstract class ZLDir {
|
|||
} else {
|
||||
return isRoot() ? myPath + itemName : myPath + getDelimiter() + itemName;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public boolean isRoot() {
|
||||
|
@ -43,6 +42,5 @@ public abstract class ZLDir {
|
|||
|
||||
abstract public ArrayList collectSubDirs();
|
||||
abstract public ArrayList collectFiles();
|
||||
|
||||
abstract protected String getDelimiter();
|
||||
}
|
||||
|
|
44
src/org/zlibrary/core/filesystem/ZLFSDir.java
Normal file
44
src/org/zlibrary/core/filesystem/ZLFSDir.java
Normal file
|
@ -0,0 +1,44 @@
|
|||
package org.zlibrary.core.filesystem;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
import org.zlibrary.core.util.*;
|
||||
|
||||
|
||||
import org.zlibrary.core.library.ZLibrary;
|
||||
|
||||
public class ZLFSDir extends ZLDir {
|
||||
private File myFile;
|
||||
|
||||
ZLFSDir(String path) {
|
||||
super(path);
|
||||
myFile = new File(path);
|
||||
}
|
||||
|
||||
public String getDelimiter() {
|
||||
return ZLibrary.getInstance().FileNameDelimiter;
|
||||
};
|
||||
|
||||
public ArrayList collectSubDirs() {
|
||||
File[] dirs = myFile.listFiles();
|
||||
ArrayList/*<String>*/ newdirs = new ArrayList();
|
||||
for(int i = 0; i < dirs.length; i++) {
|
||||
if (dirs[i].isDirectory()) {
|
||||
newdirs.add(dirs[i].getName());
|
||||
}
|
||||
}
|
||||
return newdirs;
|
||||
};
|
||||
|
||||
public ArrayList/*<String>*/ collectFiles() {
|
||||
File[] dirs = myFile.listFiles();
|
||||
ArrayList/*<String>*/ newdirs = new ArrayList();
|
||||
for(int i = 0; i < dirs.length; i++) {
|
||||
newdirs.add(dirs[i].getName());
|
||||
}
|
||||
return newdirs;
|
||||
};
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,13 +1,16 @@
|
|||
package org.zlibrary.core.filesystem;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.*;
|
||||
import org.zlibrary.core.util.*;
|
||||
|
||||
abstract class ZLFSManager {
|
||||
|
||||
import org.zlibrary.core.library.ZLibrary;
|
||||
|
||||
class ZLFSManager {
|
||||
private final HashMap myForcedFiles = new HashMap();
|
||||
protected static ZLFSManager ourInstance;
|
||||
private static ZLFSManager ourInstance;
|
||||
|
||||
public static void deleteInstance() {
|
||||
if (ourInstance != null) {
|
||||
|
@ -24,25 +27,77 @@ abstract class ZLFSManager {
|
|||
}
|
||||
|
||||
public static ZLFSManager getInstance() {
|
||||
if (ourInstance == null) {
|
||||
ourInstance = new ZLFSManager();
|
||||
}
|
||||
return ourInstance;
|
||||
}
|
||||
|
||||
|
||||
//protected ZLFSManager();
|
||||
private ZLFSManager() { }
|
||||
|
||||
|
||||
public void normalize(String path) {}
|
||||
|
||||
abstract protected InputStream createPlainInputStream(String path);
|
||||
abstract protected OutputStream createOutputStream(String path);
|
||||
//abstract protected ZLFSDir createPlainDirectory(String path);
|
||||
//abstract protected ZLFSDir createNewDirectory(String path);
|
||||
abstract protected ZLFileInfo getFileInfo(String path);
|
||||
abstract protected boolean removeFile(String path);
|
||||
abstract protected String convertFilenameToUtf8(String name);
|
||||
protected InputStream createPlainInputStream(String path) {
|
||||
return ZLibrary.getInstance().getInputStream(path);
|
||||
}
|
||||
|
||||
//public OutputStream createOutputStream(String path);
|
||||
|
||||
public ZLFSDir createPlainDirectory(String path) {
|
||||
return new ZLFSDir(path);
|
||||
}
|
||||
|
||||
public ZLFSDir createNewDirectory(String path) {
|
||||
File a = new File(path);
|
||||
a.mkdirs();
|
||||
return new ZLFSDir(path);
|
||||
}
|
||||
|
||||
protected ZLFileInfo getFileInfo(String path) {
|
||||
ZLFileInfo info = new ZLFileInfo();
|
||||
File file = new File(path);
|
||||
info.Exists = (file != null);
|
||||
info.Size = file.length();
|
||||
info.MTime = file.lastModified();
|
||||
info.IsDirectory = file.isDirectory();
|
||||
return info;
|
||||
}
|
||||
|
||||
public boolean removeFile(String path) {
|
||||
File file = new File(path);
|
||||
return file.delete();
|
||||
}
|
||||
|
||||
//TODO
|
||||
public String convertFilenameToUtf8(String name) {
|
||||
return name;
|
||||
}
|
||||
|
||||
abstract protected int findArchiveFileNameDelimiter(String path);
|
||||
abstract protected int findLastFileNameDelimiter(String path);
|
||||
abstract protected ZLDir getRootDirectory();
|
||||
abstract protected String getRootDirectoryPath();
|
||||
abstract protected String getParentPath(String path);
|
||||
public int findArchiveFileNameDelimiter(String path) {
|
||||
return path.lastIndexOf(':');
|
||||
}
|
||||
|
||||
public int findLastFileNameDelimiter(String path) {
|
||||
int index = findArchiveFileNameDelimiter(path);
|
||||
if (index == -1) {
|
||||
index = path.lastIndexOf(ZLibrary.FileNameDelimiter);
|
||||
}
|
||||
return index;
|
||||
}
|
||||
//TODO "" - windows "/"--unix
|
||||
public ZLDir getRootDirectory() {
|
||||
return createPlainDirectory("");
|
||||
|
||||
}
|
||||
|
||||
public String getRootDirectoryPath() {
|
||||
return "";
|
||||
}
|
||||
|
||||
public String getParentPath(String path) {
|
||||
File file = new File(path);
|
||||
return file.getParent();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,9 +1,16 @@
|
|||
package org.zlibrary.core.filesystem;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import org.zlibrary.core.util.*;
|
||||
|
||||
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
import java.util.zip.ZipInputStream;
|
||||
|
||||
import org.zlibrary.core.library.ZLibrary;
|
||||
|
||||
public class ZLFile {
|
||||
|
@ -81,7 +88,7 @@ public class ZLFile {
|
|||
myArchiveType = (int)(myArchiveType | ArchiveType.TAR | ArchiveType.GZIP);
|
||||
}
|
||||
}
|
||||
//(arg0)rfind
|
||||
|
||||
int index = myNameWithoutExtension.lastIndexOf('.');
|
||||
if (index > 0) {
|
||||
myExtension = myNameWithoutExtension.substring(index + 1);
|
||||
|
@ -162,13 +169,13 @@ public class ZLFile {
|
|||
return ZLibrary.getInstance().getInputStream(myHelpFileName);
|
||||
}
|
||||
|
||||
public InputStream getInputStream() {
|
||||
public InputStream getInputStream() throws IOException {
|
||||
if (isDirectory()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
InputStream stream = null;
|
||||
/*int index = ZLFSManager.getInstance().findArchiveFileNameDelimiter(myPath);
|
||||
int index = ZLFSManager.getInstance().findArchiveFileNameDelimiter(myPath);
|
||||
if (index == -1) {
|
||||
stream = ZLFSManager.getInstance().createPlainInputStream(myPath);
|
||||
} else {
|
||||
|
@ -176,7 +183,9 @@ public class ZLFile {
|
|||
InputStream base = baseFile.getInputStream();
|
||||
if (base != null) {
|
||||
if ( 0 != (baseFile.myArchiveType & ArchiveType.ZIP)) {
|
||||
//stream = new InputStream(base, myPath.substring(index + 1));
|
||||
ZipFile zf = new ZipFile(myPath.substring(0, index));
|
||||
ZipEntry entry = zf.getEntry (myPath.substring(index+1));
|
||||
stream = zf.getInputStream (entry);
|
||||
} else if (0 != (baseFile.myArchiveType & ArchiveType.TAR)) {
|
||||
//stream = new ZLTarInputStream(base, myPath.substring(index + 1));
|
||||
}
|
||||
|
@ -190,7 +199,7 @@ public class ZLFile {
|
|||
if (0 != (myArchiveType & ArchiveType.BZIP2)) {
|
||||
//return new ZLBzip2InputStream(stream);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
return stream;
|
||||
}
|
||||
//public ZLOutputStream outputStream();*/
|
||||
|
@ -203,7 +212,7 @@ public class ZLFile {
|
|||
|
||||
if (exists()) {
|
||||
if (isDirectory()) {
|
||||
//return ZLFSManager.instance().createPlainDirectory(myPath);
|
||||
return ZLFSManager.getInstance().createPlainDirectory(myPath);
|
||||
} else if (0 != (myArchiveType & ArchiveType.ZIP)) {
|
||||
//return new ZLZipDir(myPath);
|
||||
} else if (0 != (myArchiveType & ArchiveType.TAR)) {
|
||||
|
@ -211,7 +220,7 @@ public class ZLFile {
|
|||
}
|
||||
} else if (createUnexisting) {
|
||||
myInfoIsFilled = false;
|
||||
//return ZLFSManager.instance().createNewDirectory(myPath);
|
||||
return ZLFSManager.getInstance().createNewDirectory(myPath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import org.zlibrary.core.xml.ZLXMLReaderAdapter;
|
|||
public abstract class ZLibrary {
|
||||
public static final String JAR_DATA_PREFIX = "#JAR#://";
|
||||
public static String PathDelimiter;
|
||||
public static String FileNameDelimiter;
|
||||
private final HashMap myProperties = new HashMap();
|
||||
|
||||
public static ZLibrary getInstance() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue