use of org.apache.jena.atlas.AtlasException in project jena by apache.
the class RecordsFromInput method fill.
private int fill() {
try {
int len = 0;
while (len < buffer.length) {
int count = input.read(buffer, len, buffer.length - len);
if (count == -1)
break;
len += count;
}
if (len == 0)
return -1;
if (len % rowLength != 0)
throw new AtlasException("Wrong length: " + len);
return len;
} catch (IOException ex) {
throw new AtlasException(ex);
}
}
use of org.apache.jena.atlas.AtlasException in project jena by apache.
the class ProcIndexBuild method exec.
public static void exec(String locationStr, String indexName, String dataFile) {
// Argument processing
Location location = Location.create(locationStr);
//InputStream input = System.in ;
InputStream input = IO.openFile(dataFile);
int keyLength = SystemTDB.SizeOfNodeId * indexName.length();
int valueLength = 0;
// The name is the order.
String primary = indexName;
// Scope for optimization:
// Null column map => no churn.
// Do record -> record copy, not Tuple, Tuple copy.
String primaryOrder;
int dftKeyLength;
int dftValueLength;
int tupleLength = indexName.length();
if (tupleLength == 3) {
primaryOrder = Names.primaryIndexTriples;
dftKeyLength = SystemTDB.LenIndexTripleRecord;
dftValueLength = 0;
} else if (tupleLength == 4) {
primaryOrder = Names.primaryIndexQuads;
dftKeyLength = SystemTDB.LenIndexQuadRecord;
dftValueLength = 0;
} else {
throw new AtlasException("Index name: " + indexName);
}
ColumnMap colMap = new ColumnMap(primaryOrder, indexName);
// -1? Write only.
// Also flush cache every so often => block writes (but not sequential so boring).
int readCacheSize = 10;
int writeCacheSize = 100;
int blockSize = SystemTDB.BlockSize;
RecordFactory recordFactory = new RecordFactory(dftKeyLength, dftValueLength);
int order = BPlusTreeParams.calcOrder(blockSize, recordFactory);
BPlusTreeParams bptParams = new BPlusTreeParams(order, recordFactory);
int blockSizeNodes = blockSize;
int blockSizeRecords = blockSize;
FileSet destination = new FileSet(location, indexName);
BlockMgr blkMgrNodes = BlockMgrFactory.create(destination, Names.bptExtTree, blockSizeNodes, readCacheSize, writeCacheSize);
BlockMgr blkMgrRecords = BlockMgrFactory.create(destination, Names.bptExtRecords, blockSizeRecords, readCacheSize, writeCacheSize);
int rowBlock = 1000;
Iterator<Record> iter = new RecordsFromInput(input, tupleLength, colMap, rowBlock);
BPlusTree bpt2 = BPlusTreeRewriter.packIntoBPlusTree(iter, bptParams, recordFactory, blkMgrNodes, blkMgrRecords);
bpt2.close();
}
use of org.apache.jena.atlas.AtlasException in project jena by apache.
the class TokenizerText method hasNext.
@Override
public final boolean hasNext() {
if (finished)
return false;
if (token != null)
return true;
try {
skip();
if (reader.eof()) {
// close();
finished = true;
return false;
}
token = parseToken();
if (token == null) {
// close();
finished = true;
return false;
}
return true;
} catch (AtlasException ex) {
if (ex.getCause() != null) {
if (ex.getCause().getClass() == java.nio.charset.MalformedInputException.class)
throw new RiotParseException("Bad character encoding", reader.getLineNum(), reader.getColNum());
throw new RiotParseException("Bad input stream [" + ex.getCause() + "]", reader.getLineNum(), reader.getColNum());
}
throw new RiotParseException("Bad input stream", reader.getLineNum(), reader.getColNum());
}
}
use of org.apache.jena.atlas.AtlasException in project jena by apache.
the class LangEngine method nextToken.
protected final Token nextToken() {
if (eof())
return tokenEOF;
// Tokenizer errors appear here!
try {
Token t = peekIter.next();
currLine = t.getLine();
currCol = t.getColumn();
return t;
} catch (RiotParseException ex) {
// Intercept to log it.
raiseException(ex);
throw ex;
} catch (AtlasException ex) {
// Bad I/O
RiotParseException ex2 = new RiotParseException(ex.getMessage(), -1, -1);
raiseException(ex2);
throw ex2;
}
}
use of org.apache.jena.atlas.AtlasException in project jena by apache.
the class SortedDataBag method spill.
@SuppressWarnings({ "unchecked" })
protected void spill() {
// Make sure we have something to spill.
if (memory.size() > 0) {
OutputStream out;
try {
out = getSpillStream();
} catch (IOException e) {
throw new AtlasException(e);
}
// Sort the tuples as an array. The CanAbortComparator will sort
// that
// array using Arrays.sort. The cast to E[] is safe. If the sort is
// aborted, don't bother messing around with the serialisation.
// We'll
// never get around to using it anyway.
E[] array = (E[]) memory.toArray();
if (comparator.abortableSort(array) == Finish.COMPLETED) {
Sink<E> serializer = serializationFactory.createSerializer(out);
try {
for (Object tuple : array) {
serializer.send((E) tuple);
}
} finally {
serializer.close();
}
}
spilled = true;
policy.reset();
memory.clear();
}
}
Aggregations