Skip to content

Commit

Permalink
Add s3 outputstream
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinjia committed May 6, 2015
1 parent 994f995 commit e299236
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 8 deletions.
37 changes: 30 additions & 7 deletions underfs/s3/src/main/java/tachyon/underfs/s3/S3OutputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,46 @@

package tachyon.underfs.s3;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import org.jets3t.service.S3Service;
import org.jets3t.service.ServiceException;
import org.jets3t.service.model.S3Object;

import java.io.*;

public class S3OutputStream extends OutputStream {
private final String mBucketName;
private final String mKey;
private final OutputStream mOut;
private final File mFile;
private final S3Service mClient;

public S3OutputStream(String key) throws IOException {
public S3OutputStream(String bucketName, String key, S3Service client) throws IOException {
mBucketName = bucketName;
mKey = key;
File tmpFile = new File("/tmp/" + key);
mOut = new FileOutputStream(tmpFile);
mClient = client;
mFile = new File("/tmp/" + key);
mOut = new FileOutputStream(mFile);
}

@Override
public void write(int b) throws IOException {
mOut.write(b);
}

@Override
public void flush() throws IOException {
mOut.flush();
}

@Override
public void close() throws IOException {
mOut.close();
BufferedInputStream in = new BufferedInputStream(new FileInputStream(mFile));
S3Object obj = new S3Object(mKey);
try {
mClient.putObject(mBucketName, obj);
} catch (ServiceException se) {
throw new IOException(se);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public void connectFromWorker(TachyonConf conf, String hostname) {

@Override
public OutputStream create(String path) throws IOException {
return new S3OutputStream(path);
return new S3OutputStream(mBucketName, path, mClient);
}

// Same as create(path)
Expand Down

0 comments on commit e299236

Please sign in to comment.