mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
Java: add SeaweedInputStream example
This commit is contained in:
parent
c3af72d950
commit
502554887f
|
@ -26,6 +26,21 @@ public class SeaweedInputStream extends InputStream {
|
||||||
|
|
||||||
private boolean closed = false;
|
private boolean closed = false;
|
||||||
|
|
||||||
|
public SeaweedInputStream(
|
||||||
|
final FilerGrpcClient filerGrpcClient,
|
||||||
|
final String dir, final String name) throws IOException {
|
||||||
|
this.filerGrpcClient = filerGrpcClient;
|
||||||
|
this.path = dir;
|
||||||
|
FilerClient filerClient = new FilerClient(filerGrpcClient);
|
||||||
|
this.entry = filerClient.lookupEntry(dir, name);
|
||||||
|
this.contentLength = SeaweedRead.fileSize(entry);
|
||||||
|
|
||||||
|
this.visibleIntervalList = SeaweedRead.nonOverlappingVisibleIntervals(filerGrpcClient, entry.getChunksList());
|
||||||
|
|
||||||
|
LOG.debug("new path:{} entry:{} visibleIntervalList:{}", path, entry, visibleIntervalList);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public SeaweedInputStream(
|
public SeaweedInputStream(
|
||||||
final FilerGrpcClient filerGrpcClient,
|
final FilerGrpcClient filerGrpcClient,
|
||||||
final String path,
|
final String path,
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
package com.seaweedfs.examples;
|
package com.seaweedfs.examples;
|
||||||
|
|
||||||
import seaweed.hdfs.SeaweedHadoopInputStream;
|
|
||||||
import seaweedfs.client.FilerClient;
|
|
||||||
import seaweedfs.client.FilerGrpcClient;
|
import seaweedfs.client.FilerGrpcClient;
|
||||||
|
import seaweedfs.client.SeaweedInputStream;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -15,7 +14,6 @@ public class UnzipFile {
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
|
||||||
FilerGrpcClient filerGrpcClient = new FilerGrpcClient("localhost", 18888);
|
FilerGrpcClient filerGrpcClient = new FilerGrpcClient("localhost", 18888);
|
||||||
FilerClient filerClient = new FilerClient(filerGrpcClient);
|
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
parseZip("/Users/chris/tmp/test.zip");
|
parseZip("/Users/chris/tmp/test.zip");
|
||||||
|
@ -24,12 +22,8 @@ public class UnzipFile {
|
||||||
|
|
||||||
long localProcessTime = startTime2 - startTime;
|
long localProcessTime = startTime2 - startTime;
|
||||||
|
|
||||||
SeaweedHadoopInputStream seaweedInputStream = new SeaweedHadoopInputStream(
|
SeaweedInputStream seaweedInputStream = new SeaweedInputStream(
|
||||||
filerGrpcClient,
|
filerGrpcClient, "/", "test.zip");
|
||||||
new org.apache.hadoop.fs.FileSystem.Statistics(""),
|
|
||||||
"/",
|
|
||||||
filerClient.lookupEntry("/", "test.zip")
|
|
||||||
);
|
|
||||||
parseZip(seaweedInputStream);
|
parseZip(seaweedInputStream);
|
||||||
|
|
||||||
long swProcessTime = System.currentTimeMillis() - startTime2;
|
long swProcessTime = System.currentTimeMillis() - startTime2;
|
||||||
|
|
Loading…
Reference in a new issue