diff --git a/README.md b/README.md
index 0a2624e7..77a430b2 100644
--- a/README.md
+++ b/README.md
@@ -20,7 +20,7 @@ fuse for java and many file systems.
| hfs+ (dmg) | ✅ | | | | | | | | | [hfsexplorer](https://github.com/umjammer/hfsexplorer) |
| gathered | ✅ | | | | | | | | | |
| cyberduck | ✅ | | | | | | | | | [vavi-nio-file-cyberduck](https://github.com/umjammer/vavi-nio-file-cyberduck), [cyberduck](https://github.com/iterate-ch/cyberduck) |
-| discutils (vhd/ntfs) | ✅ | | | | | | | | | [vavi-nio-file-discutils](https://github.com/umjammer/vavi-nio-file-discutils) |
+| discutils (vdi/ntfs) | ✅ | | | | | | | | | [vavi-nio-file-discutils](https://github.com/umjammer/vavi-nio-file-discutils) |
# TODO
diff --git a/pom.xml b/pom.xml
index 1f77b079..3e5f8534 100644
--- a/pom.xml
+++ b/pom.xml
@@ -4,12 +4,18 @@
vavi
vavi-apps-fuse
- 0.0.6-SNAPSHOT
+ 0.0.6
jar
vavi-apps-fuse
https://github.com/umjammer/vavi-apps-fuse
- 0.0.5
+ 0.0.6
+
+ improve google drive
+ add google drive ocr capability
+ gatheredfs alias
+
+0.0.5
relive fuse-jna as generic
make onedrive (cyberduck engine) work
@@ -43,8 +49,7 @@ TODO
apple photos.app
- google automatic authentication (how to click button)
-
+ google automatic authentication (how to click button)
https://github.com/umjammer/vavi-apps-fuse
diff --git a/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java b/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java
index 10268d48..29a0d0a3 100644
--- a/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java
+++ b/src/main/java/vavi/nio/file/gathered/GatheredBasicFileAttributesProvider.java
@@ -52,6 +52,7 @@ public FileTime lastModifiedTime() {
if (FileSystem.class.isInstance(entry)) {
return FileTime.fromMillis(0);
} else if (Path.class.isInstance(entry)) {
+System.err.println("@@@: " + entry + ", " + Path.class.cast(entry).getFileSystem().provider());
return Files.getLastModifiedTime(Path.class.cast(entry));
} else {
throw new IllegalStateException("unsupported type: " + entry.getClass().getName());
diff --git a/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java b/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java
index 94cdcf86..15d47750 100644
--- a/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java
+++ b/src/main/java/vavi/nio/file/gathered/GatheredFileSystemDriver.java
@@ -34,6 +34,8 @@
import com.github.fge.filesystem.driver.UnixLikeFileSystemDriverBase;
import com.github.fge.filesystem.provider.FileSystemFactoryProvider;
+import com.google.common.collect.BiMap;
+import com.google.common.collect.HashBiMap;
import vavi.nio.file.Util;
import vavi.util.Debug;
@@ -53,15 +55,21 @@ public final class GatheredFileSystemDriver extends UnixLikeFileSystemDriverBase
/** should be unaccessible from outer */
private final Map fileSystems;
+ private BiMap nameMap;
+
/**
* @param env
*/
+ @SuppressWarnings("unchecked")
public GatheredFileSystemDriver(final FileStore fileStore,
final FileSystemFactoryProvider provider,
final Map fileSystems,
final Map env) throws IOException {
super(fileStore, provider);
this.fileSystems = fileSystems;
+ if (env.containsKey(GatheredFileSystemProvider.ENV_NAME_MAP)) {
+ this.nameMap = HashBiMap.create(Map.class.cast(env.get(GatheredFileSystemProvider.ENV_NAME_MAP)));
+ }
}
@Nonnull
@@ -144,13 +152,31 @@ public Object getPathMetadata(final Path path) throws IOException {
}
}
+ /** id -> display name */
+ private String encodeFsName(String id) throws IOException {
+ if (nameMap != null) {
+ return nameMap.get(id);
+ } else {
+ return URLEncoder.encode(id, "utf-8");
+ }
+ }
+
+ /** display name -> id */
+ private String decodeFsName(String path) throws IOException {
+ if (nameMap != null) {
+ return nameMap.inverse().get(path);
+ } else {
+ return URLDecoder.decode(path, "utf-8");
+ }
+ }
+
/** */
private List getDirectoryEntries(final Path dir) throws IOException {
if (dir.getNameCount() == 0) {
List list = new ArrayList<>(fileSystems.size());
for (String id : fileSystems.keySet()) {
- Path childPath = dir.resolve(URLEncoder.encode(id, "utf-8"));
+ Path childPath = dir.resolve(encodeFsName(id));
list.add(childPath);
}
@@ -161,12 +187,12 @@ private List getDirectoryEntries(final Path dir) throws IOException {
}
/** */
- private FileSystem getFileSystemOf(Path path) throws IOException {
+ FileSystem getFileSystemOf(Path path) throws IOException {
Debug.println("path: " + path);
if (path.getNameCount() == 0) {
return path.getFileSystem();
} else {
- String first = URLDecoder.decode(path.getName(0).toString(), "utf-8");
+ String first = decodeFsName(path.getName(0).toString());
Debug.println("first: " + first);
if (!fileSystems.containsKey(first)) {
throw new NoSuchFileException(path.toString());
diff --git a/src/main/java/vavi/nio/file/gathered/GatheredFileSystemProvider.java b/src/main/java/vavi/nio/file/gathered/GatheredFileSystemProvider.java
index 887e53f4..45880ab1 100644
--- a/src/main/java/vavi/nio/file/gathered/GatheredFileSystemProvider.java
+++ b/src/main/java/vavi/nio/file/gathered/GatheredFileSystemProvider.java
@@ -19,6 +19,8 @@ public final class GatheredFileSystemProvider extends FileSystemProviderBase {
public static final String ENV_FILESYSTEMS = "fileSystems";
+ public static final String ENV_NAME_MAP = "nameMap";
+
public GatheredFileSystemProvider() {
super(new GatheredFileSystemRepository());
}
diff --git a/src/main/java/vavi/nio/file/gathered/GatheredFileSystemRepository.java b/src/main/java/vavi/nio/file/gathered/GatheredFileSystemRepository.java
index f903a4dd..5e129d9c 100644
--- a/src/main/java/vavi/nio/file/gathered/GatheredFileSystemRepository.java
+++ b/src/main/java/vavi/nio/file/gathered/GatheredFileSystemRepository.java
@@ -49,5 +49,4 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th
GatheredFileStore fileStore = new GatheredFileStore(factoryProvider.getAttributesFactory());
return new GatheredFileSystemDriver(fileStore, factoryProvider, fileSystems, env);
}
-
}
diff --git a/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java b/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java
index bdaaf5dd..cd796a5d 100644
--- a/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java
+++ b/src/main/java/vavi/nio/file/googledrive/GoogleDriveCopyOption.java
@@ -20,16 +20,16 @@ public enum GoogleDriveCopyOption implements CopyOption {
EXPORT_AS_GDOCS("application/vnd.google-apps.document");
/** */
- private String mimeType;
+ private String value;
/** */
- private GoogleDriveCopyOption(String mimeType) {
- this.mimeType = mimeType;
+ private GoogleDriveCopyOption(String value) {
+ this.value = value;
}
/** */
- public String getMimeType() {
- return mimeType;
+ public String getValue() {
+ return value;
}
}
diff --git a/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemDriver.java b/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemDriver.java
index 442c8684..546b7e3d 100644
--- a/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemDriver.java
+++ b/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemDriver.java
@@ -90,11 +90,10 @@ public GoogleDriveFileSystemDriver(final FileStore fileStore,
{
// TODO datetime
// File root = drive.files().get("fileId=root").execute();
- entryCache.put("/", new File().setName("/").setId("root").setMimeType(MIME_TYPE_DIR).setModifiedTime(new DateTime(0)).setSize(0L));
+ entryCache.put("/", new File().setName("/").setId("root").setMimeType(MIME_TYPE_DIR).setModifiedTime(new DateTime(System.currentTimeMillis())).setSize(0L));
}
/**
- * TODO when the parent is not cached
* @see #ignoreAppleDouble
*/
public File getEntry(Path path) throws IOException {
@@ -107,14 +106,30 @@ public File getEntry(Path path) throws IOException {
throw new NoSuchFileException("ignore apple double file: " + path);
}
- File entry = drive.files().get(toPathString(path)).execute(); // TODO
+ File entry;
+ if (path.getNameCount() == 0) {
+ entry = drive.files().get(toPathString(path)).execute();
+ cache.putFile(path, entry);
+ return entry;
+ } else {
+ List siblings;
+ if (!cache.containsFolder(path.getParent())) {
+ siblings = getDirectoryEntries(path.getParent());
+ } else {
+ siblings = cache.getFolder(path.getParent());
+ }
+ for (int i = 0; i < siblings.size(); i++) { // avoid ConcurrentModificationException
+ Path p = siblings.get(i);
+ if (p.getFileName().equals(path.getFileName())) {
+ return cache.getEntry(p);
+ }
+ }
+ throw new NoSuchFileException(path.toString());
+ }
//System.err.println("GOT: path: " + path + ", id: " + entry.getId());
- cache.putFile(path, entry);
- return entry;
}
} catch (GoogleJsonResponseException e) {
if (e.getMessage().startsWith("404")) {
- // TODO when a deep directory is specified at first, like '/Books/Novels'
// cache
if (cache.containsFile(path)) {
cache.removeEntry(path);
@@ -148,9 +163,15 @@ public InputStream newInputStream(final Path path, final Set extends OpenOptio
throw new IsDirectoryException("path: " + path);
}
- // TODO
+ // TODO detect automatically?
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- drive.files().get(entry.getId()).executeMediaAndDownloadTo(baos);
+ if (options.stream().anyMatch(o -> GoogleDriveOpenOption.class.isInstance(o))) {
+ GoogleDriveOpenOption option = GoogleDriveOpenOption.class
+ .cast(options.stream().filter(o -> GoogleDriveOpenOption.class.isInstance(o)).findFirst().get());
+ drive.files().export(entry.getId(), option.getValue()).executeMediaAndDownloadTo(baos);
+ } else {
+ drive.files().get(entry.getId()).executeMediaAndDownloadTo(baos);
+ }
return new ByteArrayInputStream(baos.toByteArray());
}
@@ -171,11 +192,11 @@ public OutputStream newOutputStream(final Path path, final Set extends OpenOpt
options.forEach(o -> { System.err.println("newOutputStream: " + o); });
}
- // TODO mime type
- if (options.stream().anyMatch(o -> GoogleDriveCopyOption.class.isInstance(o))) {
- String mimeType = options.stream()
- .filter(o -> GoogleDriveCopyOption.class.isInstance(o))
- .map(o -> GoogleDriveCopyOption.class.cast(o).getMimeType()).findFirst().get();
+ // TODO detect automatically?
+ if (options.stream().anyMatch(o -> GoogleDriveOpenOption.class.isInstance(o))) {
+ @SuppressWarnings("unused")
+ GoogleDriveOpenOption option = GoogleDriveOpenOption.class
+ .cast(options.stream().filter(o -> GoogleDriveOpenOption.class.isInstance(o)).findFirst().get());
}
return new Util.OutputStreamForUploading() {
@@ -272,7 +293,7 @@ protected long getLeftOver() throws IOException {
@Override
public void close() throws IOException {
if (lock != null) {
- System.out.println("SeekableByteChannelForWriting::close: scpecial: " + path);
+System.out.println("SeekableByteChannelForWriting::close: scpecial: " + path);
return;
}
super.close();
@@ -321,7 +342,7 @@ public void copy(final Path source, final Path target, final Set opt
}
}
- copyEntry(source, target);
+ copyEntry(source, target, options);
}
@Override
@@ -464,13 +485,16 @@ private void removeEntry(Path path) throws IOException {
}
/** */
- private void copyEntry(final Path source, final Path target) throws IOException {
+ private void copyEntry(final Path source, final Path target, Set options) throws IOException {
final File sourceEntry = cache.getEntry(source);
File targetParentEntry = cache.getEntry(target.getParent());
if (!isFolder(sourceEntry)) {
File entry = new File();
entry.setName(toFilenameString(target));
entry.setParents(Arrays.asList(targetParentEntry.getId()));
+ if (options.stream().anyMatch(o -> o.equals(GoogleDriveCopyOption.EXPORT_AS_GDOCS))) {
+ entry.setMimeType(GoogleDriveCopyOption.EXPORT_AS_GDOCS.getValue());
+ }
File newEntry = drive.files().copy(sourceEntry.getId(), entry)
.setFields("id, parents, name, size, mimeType, createdTime").execute();
diff --git a/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemOptionsFactory.java b/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemOptionsFactory.java
index 034d8dfe..9b429cfc 100644
--- a/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemOptionsFactory.java
+++ b/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemOptionsFactory.java
@@ -21,6 +21,8 @@ public class GoogleDriveFileSystemOptionsFactory extends FileSystemOptionsFactor
public GoogleDriveFileSystemOptionsFactory() {
addLinkOption(LinkOption.NOFOLLOW_LINKS);
+ addCopyOption(GoogleDriveCopyOption.EXPORT_AS_GDOCS);
+ addReadOpenOption(GoogleDriveOpenOption.EXPORT_WITH_GDOCS_DOCX);
}
}
diff --git a/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemRepository.java b/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemRepository.java
index a0ee039a..2aa6a508 100644
--- a/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemRepository.java
+++ b/src/main/java/vavi/nio/file/googledrive/GoogleDriveFileSystemRepository.java
@@ -19,6 +19,8 @@
import com.github.fge.filesystem.driver.FileSystemDriver;
import com.github.fge.filesystem.provider.FileSystemRepositoryBase;
import com.google.api.client.auth.oauth2.Credential;
+import com.google.api.client.http.HttpRequest;
+import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.services.drive.Drive;
import vavi.net.auth.oauth2.google.GoogleAuthenticator;
@@ -74,8 +76,16 @@ public FileSystemDriver createDriver(final URI uri, final Map env) th
GoogleAuthenticator authenticator = getAuthenticator();
Credential credential = authenticator.authorize(email);
Drive drive = new Drive.Builder(authenticator.getHttpTransport(), authenticator.getJsonFactory(), credential)
- .setApplicationName(APPLICATION_NAME)
- .build();
+ .setHttpRequestInitializer(new HttpRequestInitializer() {
+ @Override
+ public void initialize(HttpRequest httpRequest) throws IOException {
+ credential.initialize(httpRequest);
+ httpRequest.setConnectTimeout(30 * 1000);
+ httpRequest.setReadTimeout(30 * 1000);
+ }
+ })
+ .setApplicationName(APPLICATION_NAME)
+ .build();
GoogleDriveFileStore fileStore = new GoogleDriveFileStore(drive, factoryProvider.getAttributesFactory());
return new GoogleDriveFileSystemDriver(fileStore, factoryProvider, drive, env);
diff --git a/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java b/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java
new file mode 100644
index 00000000..9c58c25d
--- /dev/null
+++ b/src/main/java/vavi/nio/file/googledrive/GoogleDriveOpenOption.java
@@ -0,0 +1,37 @@
+/*
+ * Copyright (c) 2017 by Naohide Sano, All rights reserved.
+ *
+ * Programmed by Naohide Sano
+ */
+
+package vavi.nio.file.googledrive;
+
+import java.nio.file.OpenOption;
+
+
+/**
+ * GoogleDriveOpenOption.
+ *
+ * @author Naohide Sano (umjammer)
+ * @version 0.00 2017/03/01 umjammer initial version
+ */
+public enum GoogleDriveOpenOption implements OpenOption {
+
+ EXPORT_WITH_GDOCS_DOCX("application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
+ EXPORT_WITH_GDOCS_XLSX("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
+
+ /** */
+ private String value;
+
+ /** */
+ private GoogleDriveOpenOption(String value) {
+ this.value = value;
+ }
+
+ /** */
+ public String getValue() {
+ return value;
+ }
+}
+
+/* */
diff --git a/src/main/java/vavi/nio/file/onedrive4/graph/CopyMonitorProvider.java b/src/main/java/vavi/nio/file/onedrive4/graph/CopyMonitorProvider.java
index cdd00b79..168b2ccf 100644
--- a/src/main/java/vavi/nio/file/onedrive4/graph/CopyMonitorProvider.java
+++ b/src/main/java/vavi/nio/file/onedrive4/graph/CopyMonitorProvider.java
@@ -6,7 +6,6 @@
package vavi.nio.file.onedrive4.graph;
-
import java.io.IOException;
import java.security.InvalidParameterException;
@@ -16,6 +15,7 @@
import vavi.util.Debug;
import vavi.util.StringUtil;
+
/**
* CopyMonitorProvider service provider
*
@@ -53,13 +53,13 @@ public class CopyMonitorProvider {
/**
* Creates the CopyMonitorProvider
*
- * @param copySession the initial copy session
- * @param client the Graph client
+ * @param copySession the initial copy session
+ * @param client the Graph client
* @param uploadTypeClass the upload type class
*/
public CopyMonitorProvider(final CopySession copySession,
- final IGraphServiceClient client,
- final Class uploadTypeClass) {
+ final IGraphServiceClient client,
+ final Class uploadTypeClass) {
if (copySession == null) {
throw new InvalidParameterException("Copy session is null.");
}
@@ -78,12 +78,12 @@ public CopyMonitorProvider(final CopySession copySession,
* Copy content to remote session based on the input stream
*
* @param callback the progress callback invoked during uploading
- * @param configs the optional configurations for the upload options. [0] should be the customized chunk
- * size and [1] should be the maxRetry for upload retry.
+ * @param configs the optional configurations for the upload options. [0]
+ * should be the customized chunk size and [1] should be the
+ * maxRetry for upload retry.
* @throws IOException the IO exception that occurred during upload
*/
- public void monitor(final IProgressCallback callback,
- final int...configs) throws IOException {
+ public void monitor(final IProgressCallback callback, final int... configs) throws IOException {
int timeout = DEFAULT_TIMEOUT;
@@ -101,8 +101,7 @@ public void monitor(final IProgressCallback callback,
} catch (InterruptedException e) {
}
- CopyMonitorRequest request =
- new CopyMonitorRequest(this.monitorUrl, this.client);
+ CopyMonitorRequest request = new CopyMonitorRequest(this.monitorUrl, this.client);
CopyMonitorResult result = request.monitor(this.responseHandler);
if (result.monitorDone()) {
@@ -115,7 +114,7 @@ public void monitor(final IProgressCallback callback,
MonitorType driveItem = (MonitorType) client.drive().items(monitor.resourceId).buildRequest().get();
callback.success(driveItem);
break;
- } else {
+ } else {
callback.progress(this.percentageComplete, 100);
}
} else if (result.urlHasChanged()) {
diff --git a/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java b/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java
index 4cb2e9d7..c2740b05 100644
--- a/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java
+++ b/src/main/java/vavi/nio/file/onedrive4/graph/MonitorObject.java
@@ -37,7 +37,7 @@ public class MonitorObject implements IJsonBackedObject {
@Override
public void setRawObject(ISerializer serializer, JsonObject json) {
- Debug.println(json);
+Debug.println(json);
}
private transient AdditionalDataManager additionalDataManager = new AdditionalDataManager(this);
diff --git a/src/test/java/Classification2.java b/src/test/java/Classification2.java
index d2a140ad..0444c41b 100644
--- a/src/test/java/Classification2.java
+++ b/src/test/java/Classification2.java
@@ -63,7 +63,7 @@ public static void main(final String... args) throws IOException {
for (String s : table) {
Path dir = root.resolve(s.substring(0, 1));
if (!Files.exists(dir)) {
- //System.err.println("mkdir " + dir);
+//System.err.println("mkdir " + dir);
if (!dryRun) {
Files.createDirectory(dir);
}
@@ -130,8 +130,8 @@ static class FileSearcher extends SimpleFileVisitor {
Path root;
- Pattern patternF = Pattern.compile("\\[(.+?)\\]");
- Pattern patternD = Pattern.compile("[あかさたなはまやらわ]");
+ Pattern patternF = Pattern.compile("\\[(.+?)\\]");
+ Pattern patternD = Pattern.compile("[あかさたなはまやらわ]");
FileSearcher(Path root) {
this.root = root;
diff --git a/src/test/java/GoogleOCR.java b/src/test/java/GoogleOCR.java
new file mode 100644
index 00000000..74c81847
--- /dev/null
+++ b/src/test/java/GoogleOCR.java
@@ -0,0 +1,172 @@
+/*
+ * Copyright (c) 2020 by Naohide Sano, All rights reserved.
+ *
+ * Programmed by Naohide Sano
+ */
+
+import java.io.IOException;
+import java.net.URI;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.Scanner;
+import java.util.Set;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipInputStream;
+
+import vavi.nio.file.googledrive.GoogleDriveCopyOption;
+import vavi.nio.file.googledrive.GoogleDriveOpenOption;
+import vavi.util.archive.Entry;
+import vavi.util.archive.zip.ZipArchive;
+
+
+/**
+ * google drive ocr
+ *
+ * @author Naohide Sano (umjammer)
+ * @version 0.00 2020/03/03 umjammer initial version
+ */
+public final class GoogleOCR {
+
+ /**
+ * @param args 0: email, 1: zip file, 2: extract to dir, 3: extracted dir, 4: output ocr dir
+ */
+ public static void main(final String... args) {
+ int exitCode = 0;
+ try {
+ GoogleOCR app = new GoogleOCR();
+ FileSystem fs = app.prepare(args);
+System.err.println("fs: " + fs);
+// app.extract(fs, args);
+// app.ocr(fs, args);
+ app.gather(fs, args);
+ } catch (Exception e) {
+ e.printStackTrace();
+ exitCode = -1;
+ } finally {
+//Thread.getAllStackTraces().keySet().forEach(System.err::println);
+ System.exit(exitCode);
+ }
+ }
+
+ /**
+ * @param args 0: email
+ */
+ FileSystem prepare(final String... args) throws IOException {
+ String email = args[0];
+
+ URI uri = URI.create("googledrive:///?id=" + email);
+
+ return FileSystems.newFileSystem(uri, Collections.EMPTY_MAP);
+ }
+
+ /**
+ * @param args 1: zip file, 2: extract to dir
+ */
+ void extract(FileSystem fs, final String... args) throws IOException {
+ String filename = args[1];
+ String dirname = args[2];
+// boolean dryRun = false;
+
+ Path dir = fs.getPath(dirname);
+ if (!Files.exists(dir)) {
+ Files.createDirectories(dir);
+ }
+
+ Path file = fs.getPath(filename);
+ Path tmp = Paths.get("/tmp", file.getFileName().toString());
+ if (!Files.exists(tmp)) {
+ Files.copy(file, tmp);
+System.err.println("copy: " + file + " to " + tmp);
+ }
+ ZipArchive archive = new ZipArchive(tmp.toFile());
+//int c = 0;
+ Set paths = new HashSet<>();
+ for (Entry entry : archive.entries()) {
+ Path path = dir.resolve(entry.getName());
+ if (!Files.exists(path.getParent())) {
+ Files.createDirectories(path.getParent());
+ }
+ if (!Files.exists(path)) {
+ if (entry.isDirectory()) {
+ Files.createDirectory(path);
+ } else {
+ Files.copy(archive.getInputStream(entry), path);
+ paths.add(path);
+ }
+System.err.println("extract: " + path);
+ try { Thread.sleep(300); } catch (InterruptedException e) {}
+ } else {
+System.err.println("skip: " + path);
+ }
+//if (c++ > 5) break;
+ }
+ Files.delete(tmp);
+System.err.println("rm: " + tmp);
+ }
+
+ /**
+ * @param args 3: extracted dir, 4: output ocr dir
+ */
+ void ocr(FileSystem fs, final String... args) throws IOException {
+ String extractedDirname = args[3];
+ // specify other directory avoid ConcurrentModificationException Files#list().forEach()
+ String ocrDirname = args[4];
+ Files.list(fs.getPath(extractedDirname)).forEach(p -> {
+//System.err.println(p);
+ try {
+ String fn = p.getFileName().toString();
+ if (fn.indexOf(".jpg") > 0) {
+ // gdocs doesn't have extension
+ String ocrName = fn.substring(0, fn.lastIndexOf('.')) + "_ocr"/* + fn.substring(fn.lastIndexOf('.')) */;
+ Path ocr = fs.getPath(ocrDirname).resolve(ocrName);
+ if (!Files.exists(ocr)) {
+ Path x = Files.copy(p, ocr, GoogleDriveCopyOption.EXPORT_AS_GDOCS);
+System.err.println("ocr: " + x);
+ try { Thread.sleep(1000); } catch (InterruptedException e) {}
+ } else {
+System.err.println("skip ocr: " + fn);
+ }
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ });
+ }
+
+//int c = 0;
+ /**
+ * @param args 4: output ocr dir
+ */
+ void gather(FileSystem fs, final String... args) throws IOException {
+ String ocrDirname = args[4];
+ Files.list(fs.getPath(ocrDirname)).sorted().forEach(p -> {
+//System.err.println(p);
+ try {
+ ZipInputStream zis = new ZipInputStream(Files.newInputStream(p, GoogleDriveOpenOption.EXPORT_WITH_GDOCS_DOCX));
+ ZipEntry entry;
+ while ((entry = zis.getNextEntry()) != null) {
+ if (entry.getName().equals("word/document.xml")) {
+ @SuppressWarnings("resource")
+ Scanner scanner = new Scanner(zis);
+ while (scanner.hasNextLine()) {
+ String line = scanner.nextLine();
+ line = line.replaceAll("", "\n");
+ line = line.replaceAll("<[^>]{1,}>", "");
+ line = line.replaceAll("[^[\\p{Print}]\\n]{1,}", ""); // TODO check
+ System.out.println(line);
+ }
+ }
+ zis.closeEntry();
+ }
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+//if (c++ > 1) System.exit(0);
+ });
+ }
+}
diff --git a/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java b/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java
index dfd16725..99a3c348 100644
--- a/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java
+++ b/src/test/java/vavi/nio/file/gathered/GatheredFileSystemProviderTest.java
@@ -46,6 +46,7 @@ public static void main(String[] args) throws Exception {
URI uri = URI.create("gatheredfs:///");
Map fileSystems = new HashMap<>();
+ Map nameMap = new HashMap<>();
Arrays.asList(
"googledrive:umjammer@gmail.com",
"onedrive:snaohide@hotmail.com",
@@ -53,7 +54,8 @@ public static void main(String[] args) throws Exception {
).forEach(id -> {
try {
fileSystems.put(id, app.getFileSystem(id));
-System.err.println("ADD: " + id);
+ nameMap.put(id, id.replaceAll("[:_@]", "_"));
+System.err.println("ADD: " + id + ", " + nameMap.get(id));
} catch (IOException e) {
System.err.println(e);
}
@@ -61,6 +63,7 @@ public static void main(String[] args) throws Exception {
Map env = new HashMap<>();
env.put(GatheredFileSystemProvider.ENV_FILESYSTEMS, fileSystems);
+ env.put(GatheredFileSystemProvider.ENV_NAME_MAP, nameMap);
FileSystem fs = FileSystems.newFileSystem(uri, env, Thread.currentThread().getContextClassLoader());
@@ -68,7 +71,7 @@ public static void main(String[] args) throws Exception {
options.put("fsname", "gathered_fs" + "@" + System.currentTimeMillis());
options.put("noappledouble", null);
- JavaFS.mount(fs, Paths.get(args[0]), true, false, options);
+ JavaFS.mount(fs, Paths.get(args[0]), true, false, options); // TODO not work well ???
}
/** */
@@ -118,6 +121,7 @@ private FileSystem getFileSystem(String id) throws IOException {
@Test
void test() throws IOException {
Map fileSystems = new HashMap<>();
+ Map nameMap = new HashMap<>();
Arrays.asList(
"googledrive:umjammer@gmail.com",
"onedrive:snaohide@hotmail.com",
@@ -125,7 +129,8 @@ void test() throws IOException {
).forEach(id -> {
try {
fileSystems.put(id, getFileSystem(id));
-System.err.println("ADD: " + id);
+ nameMap.put(id, id.replaceAll("[:_@]", "_"));
+System.err.println("ADD: " + id + ", " + nameMap.get(id));
} catch (IOException e) {
System.err.println(e);
}
@@ -134,11 +139,20 @@ void test() throws IOException {
URI uri = URI.create("gatheredfs:///");
Map env = new HashMap<>();
env.put(GatheredFileSystemProvider.ENV_FILESYSTEMS, fileSystems);
+ env.put(GatheredFileSystemProvider.ENV_NAME_MAP, nameMap);
FileSystem fs = FileSystems.newFileSystem(uri, env, Thread.currentThread().getContextClassLoader());
Files.list(fs.getPath("/")).forEach(p -> {
try {
- Files.list(p).forEach(System.out::println);
+// Files.list(p).forEach(System.out::println);
+ System.err.println(p.getFileName() + " " + Files.getLastModifiedTime(p));
+ Files.list(p).forEach(f -> {
+ try {
+ System.err.println(f.getFileName() + " " + Files.getLastModifiedTime(f));
+ } catch (IOException e) {
+ throw new IllegalStateException(e);
+ }
+ });
} catch (IOException e) {
throw new IllegalStateException(e);
}
diff --git a/src/test/java/vavi/nio/file/googledrive/Main.java b/src/test/java/vavi/nio/file/googledrive/Main.java
index 85773623..30fe3c2b 100644
--- a/src/test/java/vavi/nio/file/googledrive/Main.java
+++ b/src/test/java/vavi/nio/file/googledrive/Main.java
@@ -61,7 +61,7 @@ void test01() throws Exception {
URI uri = URI.create("googledrive:///?id=" + email);
- testAll(new GoogleDriveFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP));
+ testAll(new GoogleDriveFileSystemProvider().newFileSystem(uri, Collections.EMPTY_MAP));
}
// @Test