List of usage examples for java.io DataInput readInt
int readInt() throws IOException;
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void readUltraSparseBlock(DataInput in) throws IOException { allocateSparseRowsBlock(false); //adjust to size resetSparse(); //reset all sparse rows if (clen > 1) //ULTRA-SPARSE BLOCK {//from ww w .j av a 2 s . c om //block: read ijv-triples for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); int c = in.readInt(); double val = in.readDouble(); sparseBlock.allocate(r, 1, clen); sparseBlock.append(r, c, val); } } else //ULTRA-SPARSE COL { //col: read iv-pairs (should never happen since always dense) for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); double val = in.readDouble(); sparseBlock.allocate(r, 1, 1); sparseBlock.append(r, 0, val); } } }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void readUltraSparseToDense(DataInput in) throws IOException, DMLRuntimeException { allocateDenseBlock(false); //allocate block Arrays.fill(denseBlock, 0);/*from ww w. j av a 2 s. c o m*/ if (clen > 1) //ULTRA-SPARSE BLOCK { //block: read ijv-triples for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); int c = in.readInt(); double val = in.readDouble(); denseBlock[r * clen + c] = val; } } else //ULTRA-SPARSE COL { //col: read iv-pairs for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); double val = in.readDouble(); denseBlock[r] = val; } } }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private long readNnzInfo(DataInput in, boolean ultrasparse) throws IOException { //note: if ultrasparse, int always sufficient because nnz<rlen // where rlen is limited to integer long lrlen = (long) rlen; long lclen = (long) clen; //read long if required, otherwise int (see writeNnzInfo, consistency required) if (lrlen * lclen > Integer.MAX_VALUE && !ultrasparse) { nonZeros = in.readLong();//w w w. ja v a2 s . com } else { nonZeros = in.readInt(); } return nonZeros; }
From source file:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java
@Override public void readFields(DataInput in) throws IOException { //read basic header (int rlen, int clen, byte type) rlen = in.readInt(); clen = in.readInt();/* w ww. j a va 2 s. c o m*/ byte bformat = in.readByte(); //check type information if (bformat < 0 || bformat >= BlockType.values().length) throw new IOException( "invalid format: '" + bformat + "' (need to be 0-" + BlockType.values().length + ")."); BlockType format = BlockType.values()[bformat]; try { switch (format) { case ULTRA_SPARSE_BLOCK: nonZeros = readNnzInfo(in, true); sparse = evalSparseFormatInMemory(rlen, clen, nonZeros); cleanupBlock(true, true); //clean all if (sparse) readUltraSparseBlock(in); else readUltraSparseToDense(in); break; case SPARSE_BLOCK: nonZeros = readNnzInfo(in, false); sparse = evalSparseFormatInMemory(rlen, clen, nonZeros); cleanupBlock(sparse, !sparse); if (sparse) readSparseBlock(in); else readSparseToDense(in); break; case DENSE_BLOCK: sparse = false; cleanupBlock(false, true); //reuse dense readDenseBlock(in); //always dense in-mem if dense on disk break; case EMPTY_BLOCK: sparse = true; cleanupBlock(true, true); //clean all nonZeros = 0; break; } } catch (DMLRuntimeException ex) { throw new IOException("Error reading block of type '" + format.toString() + "'.", ex); } }
From source file:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java
/** * // www. java 2 s . com * @param in * @throws IOException * @throws DMLRuntimeException */ private void readSparseToDense(DataInput in) throws IOException, DMLRuntimeException { allocateDenseBlock(false); //allocate block Arrays.fill(denseBlock, 0); for (int r = 0; r < rlen; r++) { int nr = in.readInt(); for (int j = 0; j < nr; j++) { int c = in.readInt(); double val = in.readDouble(); denseBlock[r * clen + c] = val; } } }
From source file:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java
/** * // w w w. j a va 2 s. c o m * @param in * @throws IOException */ private void readUltraSparseBlock(DataInput in) throws IOException { allocateSparseRowsBlock(false); //adjust to size resetSparse(); //reset all sparse rows if (clen > 1) //ULTRA-SPARSE BLOCK { //block: read ijv-triples for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); int c = in.readInt(); double val = in.readDouble(); if (sparseRows[r] == null) sparseRows[r] = new SparseRow(1, clen); sparseRows[r].append(c, val); } } else //ULTRA-SPARSE COL { //col: read iv-pairs (should never happen since always dense) for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); double val = in.readDouble(); if (sparseRows[r] == null) sparseRows[r] = new SparseRow(1, 1); sparseRows[r].append(0, val); } } }
From source file:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java
/** * //from w ww .jav a2 s. c o m * @param in * @throws IOException * @throws DMLRuntimeException */ private void readUltraSparseToDense(DataInput in) throws IOException, DMLRuntimeException { allocateDenseBlock(false); //allocate block Arrays.fill(denseBlock, 0); if (clen > 1) //ULTRA-SPARSE BLOCK { //block: read ijv-triples for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); int c = in.readInt(); double val = in.readDouble(); denseBlock[r * clen + c] = val; } } else //ULTRA-SPARSE COL { //col: read iv-pairs for (long i = 0; i < nonZeros; i++) { int r = in.readInt(); double val = in.readDouble(); denseBlock[r] = val; } } }
From source file:com.ibm.bi.dml.runtime.matrix.data.MatrixBlock.java
/** * /*from w ww . j av a 2 s. c o m*/ * @param in * @throws IOException */ private long readNnzInfo(DataInput in, boolean ultrasparse) throws IOException { //note: if ultrasparse, int always sufficient because nnz<rlen // where rlen is limited to integer long lrlen = (long) rlen; long lclen = (long) clen; //read long if required, otherwise int (see writeNnzInfo, consistency required) if (lrlen * lclen > Integer.MAX_VALUE && !ultrasparse) { nonZeros = in.readLong(); } else { nonZeros = in.readInt(); } return nonZeros; }
From source file:org.apache.sysml.runtime.matrix.data.MatrixBlock.java
private void readSparseBlock(DataInput in) throws IOException { allocateSparseRowsBlock(false);/*from w ww . j a va 2 s .c o m*/ resetSparse(); //reset all sparse rows if (in instanceof MatrixBlockDataInput) //fast deserialize { MatrixBlockDataInput mbin = (MatrixBlockDataInput) in; nonZeros = mbin.readSparseRows(rlen, sparseBlock); } else if (in instanceof DataInputBuffer && MRJobConfiguration.USE_BINARYBLOCK_SERIALIZATION) { //workaround because sequencefile.reader.next(key, value) does not yet support serialization framework DataInputBuffer din = (DataInputBuffer) in; MatrixBlockDataInput mbin = new FastBufferedDataInputStream(din); nonZeros = mbin.readSparseRows(rlen, sparseBlock); ((FastBufferedDataInputStream) mbin).close(); } else //default deserialize { for (int r = 0; r < rlen; r++) { int rnnz = in.readInt(); //row nnz if (rnnz > 0) { sparseBlock.reset(r, rnnz, clen); for (int j = 0; j < rnnz; j++) //col index/value pairs sparseBlock.append(r, in.readInt(), in.readDouble()); } } } }
From source file:bobs.is.compress.sevenzip.SevenZFile.java
private void readFilesInfo(final DataInput header, final Archive archive) throws IOException { final long numFiles = readUint64(header); final SevenZArchiveEntry[] files = new SevenZArchiveEntry[(int) numFiles]; for (int i = 0; i < files.length; i++) { files[i] = new SevenZArchiveEntry(); }/*from w ww. j av a 2s . co m*/ BitSet isEmptyStream = null; BitSet isEmptyFile = null; BitSet isAnti = null; while (true) { final int propertyType = header.readUnsignedByte(); if (propertyType == 0) { break; } final long size = readUint64(header); switch (propertyType) { case NID.kEmptyStream: { isEmptyStream = readBits(header, files.length); break; } case NID.kEmptyFile: { if (isEmptyStream == null) { // protect against NPE throw new IOException("Header format error: kEmptyStream must appear before kEmptyFile"); } isEmptyFile = readBits(header, isEmptyStream.cardinality()); break; } case NID.kAnti: { if (isEmptyStream == null) { // protect against NPE throw new IOException("Header format error: kEmptyStream must appear before kAnti"); } isAnti = readBits(header, isEmptyStream.cardinality()); break; } case NID.kName: { final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Not implemented"); } if (((size - 1) & 1) != 0) { throw new IOException("File names length invalid"); } final byte[] names = new byte[(int) (size - 1)]; header.readFully(names); int nextFile = 0; int nextName = 0; for (int i = 0; i < names.length; i += 2) { if (names[i] == 0 && names[i + 1] == 0) { files[nextFile].setName(new String(names, nextName, i - nextName, CharsetNames.UTF_16LE)); nextName = i + 2; this.mapFilename.put(files[nextFile].getName(), nextFile); nextFile++; } } if (nextName != names.length || nextFile != files.length) { throw new IOException("Error parsing file names"); } break; } case NID.kCTime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasCreationDate(timesDefined.get(i)); if (files[i].getHasCreationDate()) { files[i].setCreationDate(Long.reverseBytes(header.readLong())); } } break; } case NID.kATime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasAccessDate(timesDefined.get(i)); if (files[i].getHasAccessDate()) { files[i].setAccessDate(Long.reverseBytes(header.readLong())); } } break; } case NID.kMTime: { final BitSet timesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasLastModifiedDate(timesDefined.get(i)); if (files[i].getHasLastModifiedDate()) { files[i].setLastModifiedDate(Long.reverseBytes(header.readLong())); } } break; } case NID.kWinAttributes: { final BitSet attributesDefined = readAllOrBits(header, files.length); final int external = header.readUnsignedByte(); if (external != 0) { throw new IOException("Unimplemented"); } for (int i = 0; i < files.length; i++) { files[i].setHasWindowsAttributes(attributesDefined.get(i)); if (files[i].getHasWindowsAttributes()) { files[i].setWindowsAttributes(Integer.reverseBytes(header.readInt())); } } break; } case NID.kStartPos: { throw new IOException("kStartPos is unsupported, please report"); } case NID.kDummy: { // 7z 9.20 asserts the content is all zeros and ignores the property // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287 if (skipBytesFully(header, size) < size) { throw new IOException("Incomplete kDummy property"); } break; } default: { // Compress up to 1.8.1 would throw an exception, now we ignore it (see COMPRESS-287 if (skipBytesFully(header, size) < size) { throw new IOException("Incomplete property of type " + propertyType); } break; } } } int nonEmptyFileCounter = 0; int emptyFileCounter = 0; for (int i = 0; i < files.length; i++) { files[i].setHasStream(isEmptyStream == null ? true : !isEmptyStream.get(i)); if (files[i].hasStream()) { files[i].setDirectory(false); files[i].setAntiItem(false); files[i].setHasCrc(archive.subStreamsInfo.hasCrc.get(nonEmptyFileCounter)); files[i].setCrcValue(archive.subStreamsInfo.crcs[nonEmptyFileCounter]); files[i].setSize(archive.subStreamsInfo.unpackSizes[nonEmptyFileCounter]); ++nonEmptyFileCounter; } else { files[i].setDirectory(isEmptyFile == null ? true : !isEmptyFile.get(emptyFileCounter)); files[i].setAntiItem(isAnti == null ? false : isAnti.get(emptyFileCounter)); files[i].setHasCrc(false); files[i].setSize(0); ++emptyFileCounter; } } archive.files = files; calculateStreamMap(archive); }