Skip to content

Commit

Permalink
Merge pull request #3 from umjammer/0.0.14
Browse files Browse the repository at this point in the history
0.0.14
  • Loading branch information
umjammer authored Oct 22, 2022
2 parents cf7d599 + f655168 commit d3020d1
Show file tree
Hide file tree
Showing 9 changed files with 276 additions and 109 deletions.
17 changes: 16 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
[![Release](https://jitpack.io/v/umjammer/vavi-nio-file.svg)](https://jitpack.io/#umjammer/vavi-nio-file) [![Java CI with Maven](https://github.com/umjammer/vavi-nio-file/workflows/Java%20CI%20with%20Maven/badge.svg)](https://github.com/umjammer/vavi-nio-file/actions) [![Parent](https://img.shields.io/badge/Parent-vavi--apps--fuse-pink)](https://github.com/umjammer/vavi-apps-fuse)
[![Release](https://jitpack.io/v/umjammer/vavi-nio-file.svg)](https://jitpack.io/#umjammer/vavi-nio-file)
[![Java CI with Maven](https://github.com/umjammer/vavi-nio-file/actions/workflows/maven.yml/badge.svg)](https://github.com/umjammer/vavi-nio-file/actions)
[![CodeQL](https://github.com/umjammer/vavi-nio-file/actions/workflows/codeql-analysis.yml/badge.svg)](https://github.com/umjammer/vavi-nio-file/actions/workflows/codeql-analysis.yml)
![Java](https://img.shields.io/badge/Java-8-b07219)
[![Parent](https://img.shields.io/badge/Parent-vavi--apps--fuse-pink)](https://github.com/umjammer/vavi-apps-fuse)

# vavi-nio-file

java nio file basics

* cache for file system
* utilities
* channels for filesystems
* input/output streams for upload/download
* output engine input stream ✭
* base test case

## TODO

* JSR-107 Cache Specification
* https://github.com/jsr107/jsr107spec
* https://github.com/ben-manes/caffeine
36 changes: 21 additions & 15 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

<groupId>vavi</groupId>
<artifactId>vavi-nio-file</artifactId>
<version>0.0.13</version>
<version>0.0.14</version>

<name>vavi-nio-file</name>
<issueManagement>
Expand All @@ -13,27 +13,24 @@
<url>https://github.com/umjammer/vavi-nio-file</url>
</scm>
<url>https://github.com/umjammer/vavi-nio-file</url>
<description>0.0.7

update utility

0.0.4

fix test base</description>
<description>java nio file basics</description>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.2</version>
<executions>
<execution>
<goals>
Expand All @@ -45,7 +42,7 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<version>3.0.0-M7</version>
<configuration>
<argLine>-Djava.util.logging.config.file=${project.build.testOutputDirectory}/logging.properties</argLine>
<trimStackTrace>false</trimStackTrace>
Expand All @@ -61,29 +58,38 @@
</repository>
</repositories>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.9.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>com.github.umjammer</groupId>
<artifactId>vavi-commons</artifactId>
<version>1.1.4</version>
<version>1.1.7</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.3.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-commons</artifactId>
<version>1.5.2</version>
<scope>test</scope>
</dependency>

Expand All @@ -100,7 +106,7 @@
<dependency>
<groupId>com.google.jimfs</groupId>
<artifactId>jimfs</artifactId>
<version>1.1</version>
<version>1.2</version>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
47 changes: 29 additions & 18 deletions src/main/java/vavi/nio/file/Cache.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,38 @@ public abstract class Cache<T> {
/** <{@link Path}, {@link List<Path>}> */
protected Map<Path, List<Path>> folderCache = new ConcurrentHashMap<>(); // TODO refresh

/** allow duplicated name in the same directory or not, e.g. google drive allows it. */
private boolean allowDuplicatedName = false;

/** sets allow duplicated name in the same directory or not */
public void setAllowDuplicatedName(boolean allowDuplicatedName) {
this.allowDuplicatedName = allowDuplicatedName;
}

/** There is metadata or not. */
public boolean containsFile(Path path) {
return entryCache.containsKey(path);
return entryCache.containsKey(path.toAbsolutePath());
}

/** raw operation for the cache */
public T getFile(Path path) {
return entryCache.get(path);
return entryCache.get(path.toAbsolutePath());
}

/** raw operation for the cache */
/** raw operation for the cache */
public T putFile(Path path, T entry) {
return entryCache.put(path, entry);
//System.err.println("CACHE.0: " + path);
return entryCache.put(path.toAbsolutePath(), entry);
}

/** There are children's metadata or not. */
public boolean containsFolder(Path path) {
return folderCache.containsKey(path);
return folderCache.containsKey(path.toAbsolutePath());
}

/** Gets children path. */
public List<Path> getFolder(Path path) {
return folderCache.get(path);
return folderCache.get(path.toAbsolutePath());
}

/**
Expand All @@ -63,38 +72,40 @@ public int getChildCount(Path path) {
return containsFolder(path) ? getFolder(path).size() : -1;
}

/** */
/** raw operation for the folder cache */
public List<Path> putFolder(Path path, List<Path> children) {
return folderCache.put(path, children);
return folderCache.put(path.toAbsolutePath(), children.stream().map(Path::toAbsolutePath).collect(Collectors.toList()));
}

/** parent folder cache will be modified */
public void addEntry(Path path, T entry) {
entryCache.put(path, entry);
//System.err.println("CACHE.1: " + path);
entryCache.put(path.toAbsolutePath(), entry);
// parent
Path parentPath = path.toAbsolutePath().getParent();
List<Path> bros = folderCache.get(parentPath);
if (bros == null) {
bros = new ArrayList<>();
folderCache.put(parentPath, bros);
List<Path> bros = folderCache.computeIfAbsent(parentPath.toAbsolutePath(), k -> new ArrayList<>());
if (!bros.contains(path.toAbsolutePath()) || allowDuplicatedName) {
//System.err.println("DIR CACHE.1: " + path);
bros.add(path.toAbsolutePath());
}
bros.add(path);
}

/** parent folder cache will be modified */
public void removeEntry(Path path) {
entryCache.remove(path);
entryCache.remove(path.toAbsolutePath());
// parent
Path parentPath = path.toAbsolutePath().getParent();
List<Path> bros = folderCache.get(parentPath);
List<Path> bros = folderCache.get(parentPath.toAbsolutePath());
if (bros != null) {
bros.remove(path);
bros.remove(path.toAbsolutePath());
}
}

/** for folder */
public void moveEntry(Path source, Path target, T entry) {
List<Path> children = getFolder(source);
if (children != null) {
folderCache.remove(source);
folderCache.remove(source.toAbsolutePath());
}
removeEntry(source);
addEntry(target, entry);
Expand Down
1 change: 0 additions & 1 deletion src/main/java/vavi/nio/file/UploadMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
/**
* UploadMonitor.
*
* TODO embed into java7-fs-base
* TODO {@link java.util.concurrent.locks.ReentrantReadWriteLock}???
*
* @author <a href="mailto:umjammer@gmail.com">Naohide Sano</a> (umjammer)
Expand Down
Loading

0 comments on commit d3020d1

Please sign in to comment.