Search in sources :

Example 1 with BinaryDataFileRandomAccess

use of org.apache.jena.dboe.base.file.BinaryDataFileRandomAccess in project jena by apache.

the class tdbdumpnodes method main.

public static void main(String... args) throws TException {
    if (args.length != 1) {
        System.err.println("Usage: tdbdumpnodes NodeFile -- e.g \"Database2/Data-0001/nodes-data.dat\"");
        System.exit(1);
    }
    String FN = args[0];
    URLConnection x;
    BinaryDataFile f = new BinaryDataFileRandomAccess(FN);
    f.open();
    TReadAppendFileTransport transport = new TReadAppendFileTransport(f);
    TProtocol protocol = TRDF.protocol(transport);
    transport.readPosition(0);
    // [0x        1BFEA0FD]
    // <http://data.europa.eu/esco/occupation/99492920-e5a5-4dba-9e5a-93193147198c>
    // [0x        1BFEA14C] ** Bad read ** don't know what type: 14
    // transport.readPosition(0x1BFEA0FD);
    long limit = f.length();
    // limit = 0x1C2092FF;
    System.out.printf("File length: %,d [0x%16X]\n", limit, limit);
    while (true) {
        long locn = transport.readPosition();
        if (locn >= limit)
            break;
        try {
            Node n = readOne(protocol);
            System.out.printf("[0x%16X] %s\n", locn, FmtUtils.stringForNode(n));
        } catch (Exception ex) {
            System.out.printf("[0x%16X] ** Bad read ** %s\n", locn, ex.getMessage());
            long jump = 100;
            long i = locn;
            for (; i < locn + jump; i++) {
                transport.readPosition(i);
                try {
                    Node n = readOne(protocol);
                    System.out.printf("Resync: %,d  [0x%16X] ==> [0x%16X]\n", i - locn, locn, i);
                    System.out.printf("[0x%16X] ** %s\n", locn, FmtUtils.stringForNode(n));
                } catch (Exception ex2) {
                }
            }
            if (locn - i >= jump)
                System.out.printf("No resync: %,d  [0x%16X] ==> [0x%16X]\n", i - locn, locn, i);
        // // Problems - back up and dump.
        // byte bytes[] = new byte[256];
        // int len = f.read(locn, bytes);
        // StringBuilder sBuff = new StringBuilder() ;
        // for ( int i = 0 ; i < len ; i++ ) {
        // byte b = bytes[i] ;
        // int hi = (b & 0xF0) >> 4 ;
        // int lo = b & 0xF ;
        // if ( i != 0 ) {
        // if (i % 20 == 0  )
        // sBuff.append("\n");
        // else
        // sBuff.append(" ");
        // }
        // sBuff.append(Chars.hexDigitsUC[hi]) ;
        // sBuff.append(Chars.hexDigitsUC[lo]) ;
        // }
        // String str = sBuff.toString();
        // if ( !str.endsWith("\n") )
        // str = str+"\n";
        // System.out.print(str);
        // System.exit(1);
        }
    }
}
Also used : BinaryDataFileRandomAccess(org.apache.jena.dboe.base.file.BinaryDataFileRandomAccess) TReadAppendFileTransport(org.apache.jena.tdb2.store.nodetable.TReadAppendFileTransport) TProtocol(org.apache.thrift.protocol.TProtocol) Node(org.apache.jena.graph.Node) BinaryDataFile(org.apache.jena.dboe.base.file.BinaryDataFile) URLConnection(java.net.URLConnection) TException(org.apache.thrift.TException)

Aggregations

URLConnection (java.net.URLConnection)1 BinaryDataFile (org.apache.jena.dboe.base.file.BinaryDataFile)1 BinaryDataFileRandomAccess (org.apache.jena.dboe.base.file.BinaryDataFileRandomAccess)1 Node (org.apache.jena.graph.Node)1 TReadAppendFileTransport (org.apache.jena.tdb2.store.nodetable.TReadAppendFileTransport)1 TException (org.apache.thrift.TException)1 TProtocol (org.apache.thrift.protocol.TProtocol)1