Search in sources :

Example 11 with AtlasException

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);
    }
}
Also used : IOException(java.io.IOException) AtlasException(org.apache.jena.atlas.AtlasException)

Example 12 with AtlasException

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();
}
Also used : ColumnMap(org.apache.jena.tdb.lib.ColumnMap) BPlusTreeParams(org.apache.jena.tdb.index.bplustree.BPlusTreeParams) FileSet(org.apache.jena.tdb.base.file.FileSet) InputStream(java.io.InputStream) AtlasException(org.apache.jena.atlas.AtlasException) RecordFactory(org.apache.jena.tdb.base.record.RecordFactory) BlockMgr(org.apache.jena.tdb.base.block.BlockMgr) Record(org.apache.jena.tdb.base.record.Record) BPlusTree(org.apache.jena.tdb.index.bplustree.BPlusTree) Location(org.apache.jena.tdb.base.file.Location)

Example 13 with AtlasException

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());
    }
}
Also used : RiotParseException(org.apache.jena.riot.RiotParseException) AtlasException(org.apache.jena.atlas.AtlasException)

Example 14 with AtlasException

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;
    }
}
Also used : RiotParseException(org.apache.jena.riot.RiotParseException) Token(org.apache.jena.riot.tokens.Token) AtlasException(org.apache.jena.atlas.AtlasException)

Example 15 with AtlasException

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();
    }
}
Also used : OutputStream(java.io.OutputStream) IOException(java.io.IOException) AtlasException(org.apache.jena.atlas.AtlasException)

Aggregations

AtlasException (org.apache.jena.atlas.AtlasException)27 IOException (java.io.IOException)5 FileNotFoundException (java.io.FileNotFoundException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 RiotParseException (org.apache.jena.riot.RiotParseException)3 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 Token (org.apache.jena.riot.tokens.Token)2 BufferedInputStream (java.io.BufferedInputStream)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 Iterator (java.util.Iterator)1 InStreamUTF8 (org.apache.jena.atlas.io.InStreamUTF8)1 InputStreamBuffered (org.apache.jena.atlas.io.InputStreamBuffered)1 IteratorResourceClosing (org.apache.jena.atlas.iterator.IteratorResourceClosing)1 ProgressMonitor (org.apache.jena.atlas.lib.ProgressMonitor)1 BlockMgr (org.apache.jena.tdb.base.block.BlockMgr)1 FileSet (org.apache.jena.tdb.base.file.FileSet)1 Location (org.apache.jena.tdb.base.file.Location)1