Search in sources :

Example 1 with RandomAccessFile

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;
}
Also used : GATContext(org.gridlab.gat.GATContext) RandomAccessFile(org.gridlab.gat.io.RandomAccessFile) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) Preferences(org.gridlab.gat.Preferences)

Example 2 with RandomAccessFile

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;
    }
}
Also used : RandomAccessFile(org.gridlab.gat.io.RandomAccessFile) GATObjectCreationException(org.gridlab.gat.GATObjectCreationException) IOException(java.io.IOException)

Aggregations

GATObjectCreationException (org.gridlab.gat.GATObjectCreationException)2 RandomAccessFile (org.gridlab.gat.io.RandomAccessFile)2 IOException (java.io.IOException)1 GATContext (org.gridlab.gat.GATContext)1 Preferences (org.gridlab.gat.Preferences)1