use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method readTest2.
/**
* Tests {@link FileInStream#read(byte[])}.
*/
@Test
public void readTest2() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
String filename = sTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
byte[] ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
ret = new byte[k];
Assert.assertEquals(k, is.read(ret));
Assert.assertTrue(BufferUtils.equalIncreasingByteArray(k, ret));
is.close();
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class FileInStreamIntegrationTest method seek.
/**
* Tests {@link FileInStream#seek(long)}.
*/
@Test
public void seek() throws Exception {
for (int k = MIN_LEN; k <= MAX_LEN; k += DELTA) {
for (CreateFileOptions op : getOptionSet()) {
String filename = sTestPath + "/file_" + k + "_" + op.hashCode();
AlluxioURI uri = new AlluxioURI(filename);
FileInStream is = sFileSystem.openFile(uri, FileSystemTestUtils.toOpenFileOptions(op));
is.seek(k / 3);
Assert.assertEquals(k / 3, is.read());
is.seek(k / 2);
Assert.assertEquals(k / 2, is.read());
is.seek(k / 4);
Assert.assertEquals(k / 4, is.read());
is.close();
}
}
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class ReadOnlyMountIntegrationTest method openFile.
@Test
public void openFile() throws IOException, AlluxioException {
AlluxioURI fileUri = new AlluxioURI(FILE_PATH);
mFileSystem.loadMetadata(fileUri);
FileInStream inStream = mFileSystem.openFile(fileUri);
Assert.assertNotNull(inStream);
inStream.close();
fileUri = new AlluxioURI(SUB_FILE_PATH);
mFileSystem.loadMetadata(fileUri, LoadMetadataOptions.defaults().setRecursive(true));
inStream = mFileSystem.openFile(fileUri);
Assert.assertNotNull(inStream);
inStream.close();
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class LoadCommand method load.
/**
* Loads a file or directory in Alluxio space, makes it resident in memory.
*
* @param filePath The {@link AlluxioURI} path to load into Alluxio memory
* @throws AlluxioException when Alluxio exception occurs
* @throws IOException when non-Alluxio exception occurs
*/
private void load(AlluxioURI filePath) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(filePath);
if (status.isFolder()) {
List<URIStatus> statuses = mFileSystem.listStatus(filePath);
for (URIStatus uriStatus : statuses) {
AlluxioURI newPath = new AlluxioURI(uriStatus.getPath());
load(newPath);
}
} else {
if (status.getInMemoryPercentage() == 100) {
// The file has already been fully loaded into Alluxio memory.
return;
}
Closer closer = Closer.create();
try {
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.CACHE_PROMOTE);
FileInStream in = closer.register(mFileSystem.openFile(filePath, options));
byte[] buf = new byte[8 * Constants.MB];
while (in.read(buf) != -1) {
}
} catch (Exception e) {
throw closer.rethrow(e);
} finally {
closer.close();
}
}
System.out.println(filePath + " loaded");
}
use of alluxio.client.file.FileInStream in project alluxio by Alluxio.
the class CatCommand method runCommand.
@Override
protected void runCommand(AlluxioURI path, CommandLine cl) throws AlluxioException, IOException {
URIStatus status = mFileSystem.getStatus(path);
if (status.isFolder()) {
throw new FileDoesNotExistException(ExceptionMessage.PATH_MUST_BE_FILE.getMessage(path));
}
OpenFileOptions options = OpenFileOptions.defaults().setReadType(ReadType.NO_CACHE);
byte[] buf = new byte[512];
try (FileInStream is = mFileSystem.openFile(path, options)) {
int read = is.read(buf);
while (read != -1) {
System.out.write(buf, 0, read);
read = is.read(buf);
}
}
}
Aggregations