Example usage for java.io DataInput readBoolean

List of usage examples for java.io DataInput readBoolean

Introduction

In this page you can find the example usage for java.io DataInput readBoolean.

Prototype

boolean readBoolean() throws IOException;

Source Link

Document

Reads one input byte and returns true if that byte is nonzero, false if that byte is zero.

Usage

From source file:org.fastcatsearch.ir.document.DocumentWriter.java

public Document readDocument(int docNo) throws IOException, IRException {
    long prevPosPos = positionOutput.position();
    long docPos = -1;
    try {/*from   ww  w .  j  a  v a2 s  . c o m*/
        long positionOffset = ((long) docNo) * IOUtil.SIZE_OF_LONG;
        positionOutput.seek(positionOffset);
        docPos = IOUtil.readLong(positionOutput.getRaf());
    } finally {
        positionOutput.seek(prevPosPos);
    }

    // find a document block
    long prevDocPos = docOutput.position();
    try {
        docOutput.seek(docPos);
        RandomAccessFile raf = docOutput.getRaf();
        int len = IOUtil.readInt(raf);
        long n = raf.getFilePointer();
        InputStream docInput = Channels.newInputStream(docOutput.getRaf().getChannel().position(n));
        //2014-11-26 ?  working ?   ? ? GC ?? OOM ? ?.
        // Stream  .
        InflaterInputStream decompressInputStream = null;
        inflaterOutput.reset();
        int count = -1;
        try {
            BoundedInputStream boundedInputStream = new BoundedInputStream(docInput, len);
            boundedInputStream.setPropagateClose(false);// docInput  .
            decompressInputStream = new InflaterInputStream(boundedInputStream, new Inflater(), 512);
            while ((count = decompressInputStream.read(workingBuffer)) != -1) {
                inflaterOutput.write(workingBuffer, 0, count);
            }
        } finally {
            decompressInputStream.close();
        }
    } finally {
        docOutput.seek(prevDocPos);
    }

    BytesRef bytesRef = inflaterOutput.getBytesRef();
    DataInput bai = new BytesDataInput(bytesRef.bytes, 0, bytesRef.length);

    Document document = new Document(fields.size());
    for (int i = 0; i < fields.size(); i++) {
        FieldSetting fs = fields.get(i);
        Field f = null;
        boolean hasValue = bai.readBoolean();
        if (hasValue) {
            f = fs.createEmptyField();
            f.readRawFrom(bai);
        } else {
            f = fs.createEmptyField();
        }
        if (f != null) {
            String multiValueDelimiter = fs.getMultiValueDelimiter();
            try {
                f.parseIndexable(multiValueDelimiter);
            } catch (FieldDataParseException e) {
                throw new IOException(e);
            }
        }
        document.add(f);
    }
    document.setDocId(docNo);
    return document;
}

From source file:org.lilyproject.repository.impl.hbase.LilyFieldSingleColumnValueFilter.java

public void readFields(final DataInput in) throws IOException {
    this.columnFamily = Bytes.readByteArray(in);
    if (this.columnFamily.length == 0) {
        this.columnFamily = null;
    }//from  ww w  .j  a  v  a2 s .c  om
    this.columnQualifier = Bytes.readByteArray(in);
    if (this.columnQualifier.length == 0) {
        this.columnQualifier = null;
    }
    this.compareOp = CompareFilter.CompareOp.valueOf(in.readUTF());
    this.comparator = (WritableByteArrayComparable) HbaseObjectWritable.readObject(in, null);
    this.foundColumn = in.readBoolean();
    this.matchedColumn = in.readBoolean();
    this.filterIfMissing = in.readBoolean();
    this.latestVersionOnly = in.readBoolean();
}

From source file:parquet.hadoop.ParquetInputSplit.java

private BlockMetaData readBlock(DataInput in) throws IOException {
    final BlockMetaData block = new BlockMetaData();
    int size = in.readInt();
    for (int i = 0; i < size; i++) {
        block.addColumn(readColumn(in));
    }/*  www  .ja  va  2 s. co m*/
    block.setRowCount(in.readLong());
    block.setTotalByteSize(in.readLong());
    if (!in.readBoolean()) {
        block.setPath(in.readUTF().intern());
    }
    return block;
}

From source file:PFPGrowth_in_SPARK.TransactionTree.java

public void readFields(DataInput in) throws IOException {
    representedAsList = in.readBoolean();

    VIntWritable vInt = new VIntWritable();
    VLongWritable vLong = new VLongWritable();

    if (representedAsList) {
        transactionSet = Lists.newArrayList();
        vInt.readFields(in);//from   w  w  w .j av a 2s  . c om
        int numTransactions = vInt.get();
        for (int i = 0; i < numTransactions; i++) {
            vLong.readFields(in);
            Long support = vLong.get();

            vInt.readFields(in);
            int length = vInt.get();

            int[] items = new int[length];
            for (int j = 0; j < length; j++) {
                vInt.readFields(in);
                items[j] = vInt.get();
            }
            Pair<IntArrayList, Long> transaction = new Pair<IntArrayList, Long>(new IntArrayList(items),
                    support);
            transactionSet.add(transaction);
        }
    } else {
        vInt.readFields(in);
        nodes = vInt.get();
        attribute = new int[nodes];
        nodeCount = new long[nodes];
        childCount = new int[nodes];
        nodeChildren = new int[nodes][];
        for (int i = 0; i < nodes; i++) {
            vInt.readFields(in);
            attribute[i] = vInt.get();
            vLong.readFields(in);
            nodeCount[i] = vLong.get();
            vInt.readFields(in);
            int childCountI = vInt.get();
            childCount[i] = childCountI;
            nodeChildren[i] = new int[childCountI];
            for (int j = 0; j < childCountI; j++) {
                vInt.readFields(in);
                nodeChildren[i][j] = vInt.get();
            }
        }
    }
}

From source file:uk.ac.gla.terrier.probos.Utils.java

public static String readStringOrNull(DataInput in) throws IOException {
    if (!in.readBoolean())
        return null;
    return in.readUTF();
}