use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class S3RestServiceHandler method getObject.
private Response getObject(final FileSystem fs, final String bucket, final String object, final String range) {
return S3RestUtils.call(bucket, () -> {
String bucketPath = S3RestUtils.parsePath(AlluxioURI.SEPARATOR + bucket);
S3RestUtils.checkPathIsAlluxioDirectory(fs, bucketPath);
String objectPath = bucketPath + AlluxioURI.SEPARATOR + object;
AlluxioURI objectURI = new AlluxioURI(objectPath);
try {
URIStatus status = fs.getStatus(objectURI);
FileInStream is = fs.openFile(objectURI);
S3RangeSpec s3Range = S3RangeSpec.Factory.create(range);
RangeFileInStream ris = RangeFileInStream.Factory.create(is, status.getLength(), s3Range);
// TODO(cc): Consider how to respond with the object's ETag.
return Response.ok(ris).lastModified(new Date(status.getLastModificationTimeMs())).header(S3Constants.S3_ETAG_HEADER, "\"" + status.getLastModificationTimeMs() + "\"").header(S3Constants.S3_CONTENT_LENGTH_HEADER, s3Range.getLength(status.getLength())).build();
} catch (Exception e) {
throw S3RestUtils.toObjectS3Exception(e, objectPath);
}
});
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class AlluxioJniFuseFileSystem method flushInternal.
private int flushInternal(String path, FuseFileInfo fi) {
final long fd = fi.fh.get();
FileInStream is = mOpenFileEntries.get(fd);
CreateFileEntry<FileOutStream> ce = mCreateFileEntries.getFirstByField(ID_INDEX, fd);
if (ce == null && is == null) {
LOG.error("Cannot find fd for {} in table", path);
return -ErrorCodes.EBADFD();
}
if (ce == null) {
// flush() may be called in places other than write
return 0;
}
try {
synchronized (ce) {
ce.getOut().flush();
}
} catch (Throwable e) {
LOG.error("Failed to flush {}", path, e);
return -ErrorCodes.EIO();
}
return 0;
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class AlluxioFuseFileSystemTest method openWithoutDelay.
@Test
public void openWithoutDelay() throws Exception {
AlluxioURI expectedPath = BASE_EXPECTED_URI.join("/foo/bar");
setUpOpenMock(expectedPath);
FileInStream is = mock(FileInStream.class);
when(mFileSystem.openFile(expectedPath)).thenReturn(is);
mFuseFs.open("/foo/bar", mFileInfo);
verify(mFileSystem).openFile(expectedPath);
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class TailCommand method runPlainPath.
@Override
protected void runPlainPath(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
int numOfBytes = Constants.KB;
if (cl.hasOption('c')) {
numOfBytes = (int) FormatUtils.parseSpaceSize(cl.getOptionValue('c'));
Preconditions.checkArgument(numOfBytes > 0, "specified bytes must be > 0");
}
if (status.isFolder()) {
throw new IOException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
}
try (FileInStream is = mFileSystem.openFile(path)) {
byte[] buf = new byte[numOfBytes];
long bytesToRead;
if (status.getLength() > numOfBytes) {
bytesToRead = numOfBytes;
} else {
bytesToRead = status.getLength();
}
is.skip(status.getLength() - bytesToRead);
int read = is.read(buf);
if (read != -1) {
System.out.write(buf, 0, read);
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class CpCommandIntegrationTest method copyFromLocalLarge.
@Test
public void copyFromLocalLarge() throws Exception {
File testFile = new File(sLocalAlluxioCluster.getAlluxioHome() + "/testFile");
testFile.delete();
testFile.createNewFile();
FileOutputStream fos = new FileOutputStream(testFile);
byte[] toWrite = BufferUtils.getIncreasingByteArray(SIZE_BYTES);
fos.write(toWrite);
fos.close();
String[] cmd = new String[] { "cp", "file://" + testFile.getAbsolutePath(), "/testFile" };
sFsShell.run(cmd);
Assert.assertEquals(getCommandOutput(cmd), mOutput.toString());
AlluxioURI uri = new AlluxioURI("/testFile");
URIStatus status = sFileSystem.getStatus(uri);
Assert.assertNotNull(status);
Assert.assertEquals(SIZE_BYTES, status.getLength());
try (FileInStream tfis = sFileSystem.openFile(uri, OpenFilePOptions.newBuilder().setReadType(ReadPType.NO_CACHE).build())) {
byte[] read = new byte[SIZE_BYTES];
tfis.read(read);
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(SIZE_BYTES, read));
}
}
Aggregations