Skip to content

Commit

Permalink
Merge bfd5855 into c45dbfe
Browse files Browse the repository at this point in the history
  • Loading branch information
tamada committed Feb 16, 2017
2 parents c45dbfe + bfd5855 commit 96ffbf6
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 3 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/github/kunai/entries/Entry.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ default boolean isClass(){
return name.endsWith(".class");
}

boolean endsWith(String suffix);

boolean isName(String name);

default URI loadFrom(){
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/github/kunai/entries/PathEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ public InputStream openStream() throws IOException{
return source.openStream(path);
}

public boolean isName(Name name){
return path.endsWith(name.toString());
@Override
public boolean endsWith(String suffix){
return path.toString()
.endsWith(suffix);
}

@Override
public boolean isName(String name){
return isName(new Name(name));
return path.endsWith(name);
}

@Override
Expand Down
39 changes: 39 additions & 0 deletions src/main/java/com/github/kunai/source/PlainFileDataSource.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.github.kunai.source;

import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.stream.Stream;

import com.github.kunai.entries.ClassName;
import com.github.kunai.entries.Entry;
import com.github.kunai.entries.PathEntry;

public class PlainFileDataSource extends AbstractDataSource implements PathResolver{
private Path path;

public PlainFileDataSource(Path path){
this.path = path;
}

@Override
public Stream<Entry> stream() {
return Stream.of(new PathEntry(path, this));
}

@Override
public void close() throws IOException {
// do nothing.
}

@Override
public InputStream openStream(Path path) throws IOException {
return Files.newInputStream(path);
}

@Override
public ClassName parseClassName(Path path) {
return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public DataSourceFactories(){
factories.add(new WarFileDataSourceFactory());
factories.add(new ClassFileDataSourceFactory());
factories.add(new DirectoryDataSourceFactory());
factories.add(new PlainFileDataSourceFactory());
}

public Optional<DataSourceFactory> find(Path path) throws IOException{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.github.kunai.source.factories;

import java.nio.file.FileSystem;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;

import com.github.kunai.entries.KunaiException;
import com.github.kunai.source.DataSource;
import com.github.kunai.source.PlainFileDataSource;

class PlainFileDataSourceFactory implements DataSourceFactory{
public PlainFileDataSourceFactory(){
}

@Override
public boolean isTarget(Path path, FileSystem system, BasicFileAttributes attributes){
return attributes.isRegularFile();
}

@Override
public DataSource build(Path path, FileSystem system) throws KunaiException{
return new PlainFileDataSource(path);
}
}

0 comments on commit 96ffbf6

Please sign in to comment.