use of org.gridlab.gat.io.RandomAccessFile in project compss by bsc-wdc.
the class RandomAccessFileAdaptorTest method test.
public AdaptorTestResult test(String adaptor, String host) {
AdaptorTestResult adaptorTestResult = new AdaptorTestResult(adaptor, host);
GATContext gatContext = new GATContext();
Preferences preferences = new Preferences();
preferences.put("randomaccessfile.adaptor.name", adaptor);
RandomAccessFile randomAccessFile = null;
try {
randomAccessFile = GAT.createRandomAccessFile(gatContext, preferences, "any://" + host + "/JavaGAT-random-accessfile", "rw");
} catch (GATObjectCreationException e) {
e.printStackTrace();
GAT.end();
System.exit(1);
}
adaptorTestResult.put("length ", lengthTest(gatContext, preferences, randomAccessFile, 0));
adaptorTestResult.put("write 'lorem ipsum'", writeTest(gatContext, preferences, randomAccessFile, "lorem ipsum"));
adaptorTestResult.put("length after write", lengthTest(gatContext, preferences, randomAccessFile, 13));
adaptorTestResult.put("seek ", seekTest(gatContext, preferences, randomAccessFile, 0));
adaptorTestResult.put("read ", readTest(gatContext, preferences, randomAccessFile, "lorem ipsum"));
adaptorTestResult.put("write 'lorem ipsum' 2", writeTest(gatContext, preferences, randomAccessFile, "lorem ipsum"));
adaptorTestResult.put("length after write 2", lengthTest(gatContext, preferences, randomAccessFile, 26));
adaptorTestResult.put("seek 2 ", seekTest(gatContext, preferences, randomAccessFile, 0));
adaptorTestResult.put("read 2 ", readTest(gatContext, preferences, randomAccessFile, "lorem ipsum"));
adaptorTestResult.put("read 3 ", readTest(gatContext, preferences, randomAccessFile, "lorem ipsum"));
return adaptorTestResult;
}
use of org.gridlab.gat.io.RandomAccessFile in project compss by bsc-wdc.
the class RandomAccessFileExample method start.
public void start(String source, String target) {
RandomAccessFile sourceFile = null;
try {
sourceFile = GAT.createRandomAccessFile(source, "r");
} catch (GATObjectCreationException e) {
System.err.println("Failed to create random access file '" + source + "': " + e);
return;
}
RandomAccessFile targetFile = null;
try {
targetFile = GAT.createRandomAccessFile(target, "rw");
} catch (GATObjectCreationException e) {
System.err.println("Failed to create random access file '" + target + "': " + e);
return;
}
try {
targetFile.setLength(sourceFile.length());
} catch (IOException e) {
System.err.println("Failed to set/get the length: " + e);
return;
}
try {
for (int i = 0; i < sourceFile.length(); i++) {
targetFile.seek(targetFile.length() - 1 - i);
sourceFile.seek(i);
targetFile.writeByte(sourceFile.readByte());
}
} catch (IOException e) {
System.out.println("Failed to seek/read/write: " + e);
return;
}
}
Aggregations