use of org.apache.jena.tdb2.store.nodetable.TReadAppendFileTransport 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);
}
}
}
Aggregations