Search in sources :

Example 1 with StructureKey

use of com.ibm.j9ddr.tools.store.StructureKey in project openj9 by eclipse.

the class J9DDRStructureStoreTest method add.

@Test
public void add() {
    // Test
    J9DDRStructureStore store = null;
    try {
        store = new J9DDRStructureStore("newDir", "superset.dat");
    } catch (IOException e) {
        e.printStackTrace();
        fail("Could not open store");
    }
    String original = "E:\\workspaces\\j9ddr\\DDR_VM\\data\\structure blobs\\j9ddr.dat";
    String newOne = "E:\\workspaces\\j9ddr\\DDR_VM\\data\\structure blobs\\newj9ddr.dat";
    StructureKey keyOne = new StructureKey("windows", "foo");
    StructureKey keyTwo = new StructureKey("windows", "bar");
    // String structureFileName = original;
    // StructureKey key = keyOne;
    String structureFileName = newOne;
    StructureKey key = keyTwo;
    try {
        store.add(key, structureFileName, true);
        store.close();
    } catch (IOException e) {
        e.printStackTrace();
        fail(e.getMessage());
    } catch (StructureMismatchError e) {
        e.printStackTrace();
        fail(e.getMessage());
    } finally {
        try {
            store.close();
        } catch (IOException e) {
            fail("Could not close store");
        }
    }
    // TODO: Open file and make sure it is good.
    try {
        store.close();
        store = null;
        store = new J9DDRStructureStore("newDir", "superset.dat");
        ImageInputStream is = store.get(key);
        FileInputStream fis = new FileInputStream(structureFileName);
        assertTrue("Files where not the same", compare(is, fis));
    } catch (IOException e) {
        fail();
    }
}
Also used : StructureKey(com.ibm.j9ddr.tools.store.StructureKey) J9DDRStructureStore(com.ibm.j9ddr.tools.store.J9DDRStructureStore) ImageInputStream(javax.imageio.stream.ImageInputStream) StructureMismatchError(com.ibm.j9ddr.tools.store.StructureMismatchError) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 2 with StructureKey

use of com.ibm.j9ddr.tools.store.StructureKey in project openj9 by eclipse.

the class AddStructureBlob method addFromPropertiesFile.

// the order in which files are added is controlled by a properties file, it expects the -f parameter to point to a directory containg
// either blobs or supersets
private void addFromPropertiesFile(J9DDRStructureStore store) throws IOException, StructureMismatchError {
    String directoryName = opts.get("-d");
    String keyString = opts.get("-k");
    File structurePath = new File(opts.get("-f"));
    // load the spec order (if specified on the command line)
    String[] specs = loadSpecNames();
    File[] structureFiles = new File[specs.length];
    for (int i = 0; i < specs.length; i++) {
        structureFiles[i] = new File(structurePath, specs[i]);
    }
    for (File file : structureFiles) {
        if (file.exists()) {
            StructureKey key = new StructureKey(file.getName() + "." + keyString);
            store.add(key, file.getPath(), false);
            store.updateSuperset();
            System.out.println(String.format("Added %s to %s/%s as %s", file.getAbsolutePath(), directoryName, store.getSuperSetFileName(), key));
        } else {
            System.out.println("WARNING : The specified structure file " + file.getName() + " does not exist and was ignored");
        }
    }
}
Also used : StructureKey(com.ibm.j9ddr.tools.store.StructureKey) File(java.io.File)

Example 3 with StructureKey

use of com.ibm.j9ddr.tools.store.StructureKey in project openj9 by eclipse.

the class AddStructureBlob method addFromFile.

// add a structure from a specified path
private void addFromFile(J9DDRStructureStore store) throws IOException, StructureMismatchError {
    String directoryName = opts.get("-d");
    String structureName = opts.get("-f");
    String keyString = opts.get("-k");
    String supersetName = opts.get("-s");
    if (keyString == null) {
        File structurePath = new File(structureName);
        File[] structureFiles;
        if (structurePath.isDirectory()) {
            structureFiles = structurePath.listFiles();
        } else {
            structureFiles = new File[] { structurePath };
            structurePath = structurePath.getParentFile();
        }
        for (File file : structureFiles) {
            if (file.exists()) {
                store.add(null, file.getPath(), false);
                store.updateSuperset();
                System.out.println("Added " + file.getName() + " to superset " + supersetName + " in " + directoryName);
            } else {
                System.out.println("WARNING : The specified structure file " + file.getName() + " does not exist and was ignored");
            }
        }
    } else {
        StructureKey key = new StructureKey(keyString);
        store.add(key, structureName, true);
        store.updateSuperset();
        System.out.println(String.format("Added %s to %s/%s as %s", structureName, directoryName, store.getSuperSetFileName(), keyString));
    }
}
Also used : StructureKey(com.ibm.j9ddr.tools.store.StructureKey) File(java.io.File)

Aggregations

StructureKey (com.ibm.j9ddr.tools.store.StructureKey)3 File (java.io.File)2 J9DDRStructureStore (com.ibm.j9ddr.tools.store.J9DDRStructureStore)1 StructureMismatchError (com.ibm.j9ddr.tools.store.StructureMismatchError)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ImageInputStream (javax.imageio.stream.ImageInputStream)1 Test (org.junit.Test)1