private static boolean isBinaryATerm(final BitStream in) throws IOException { try { final int w1 = in.readInt(); return w1 == BAF_MAGIC; } catch (final EOFException e) { _logger.log(Level.FINE, "", e); } return false; }
int val = _reader.readBits(e.symWidth[i]); if (isDebugging()) val = _reader.readBits(argSym.termWidth); if (argSym.terms[val] == null) final int val = _reader.readBits(HEADER_BITS); _level--; return _factory.makeInt(val); _reader.flushBitsFromReader(); final String s = _reader.readString(); _level--; return _factory.makeReal(new Double(s).doubleValue());
public int readInt() throws IOException { final int[] buf = new int[5]; buf[0] = readByte(); // Check if 1st character is enough if ((buf[0] & 0x80) == 0) return buf[0]; buf[1] = readByte(); // Check if 2nd character is enough if ((buf[0] & 0x40) == 0) return buf[1] + ((buf[0] & ~0xc0) << 8); buf[2] = readByte(); // Check if 3rd character is enough if ((buf[0] & 0x20) == 0) return buf[2] + (buf[1] << 8) + ((buf[0] & ~0xe0) << 16); buf[3] = readByte(); // Check if 4th character is enough if ((buf[0] & 0x10) == 0) return buf[3] + (buf[2] << 8) + (buf[1] << 16) + ((buf[0] & ~0xf0) << 24); buf[4] = readByte(); return buf[4] + (buf[3] << 8) + (buf[2] << 16) + (buf[1] << 24); }
public int readBits(final int nrBits) throws IOException { int mask = 1; int val = 0; for (int i = 0; i < nrBits; i++) { if (_bitsInBuffer == 0) { final int v = readByte(); if (v == -1) return -1; _bitBuffer = v; _bitsInBuffer = 8; } val |= (_bitBuffer & 0x80) != 0 ? mask : 0; mask <<= 1; _bitBuffer <<= 1; _bitsInBuffer--; } return val; }
public ATerm readFromBinaryFile(final boolean headerAlreadyRead) throws ParseError, IOException { if (!headerAlreadyRead && !isBinaryATerm(_reader)) throw new ParseError("Input is not a BAF file"); final int val = _reader.readInt(); if (val != BAF_VERSION) throw new ParseError("Wrong BAF version (wanted " + BAF_VERSION + ", got " + val + "), giving up"); _nrUniqueSymbols = _reader.readInt(); final int nrUniqueTerms = _reader.readInt(); if (isDebugging()) { debug("" + _nrUniqueSymbols + " unique symbols"); debug("" + nrUniqueTerms + " unique terms"); } _symbols = new SymEntry[_nrUniqueSymbols]; readAllSymbols(); final int i = _reader.readInt(); return readTerm(_symbols[i]); }
private AFun readSymbol() throws IOException { final String s = _reader.readString(); final int arity = _reader.readInt(); final int quoted = _reader.readInt(); if (isDebugging()) debug(s + " / " + arity + " / " + quoted); return _factory.makeAFun(s, arity, quoted != 0); }
public String readString() throws IOException { final int l = readInt(); final byte[] b = new byte[l]; int v = 0; while (v < b.length) v += _stream.read(b, v, b.length - v); return new String(b); }
public BAFReader(final PureFactory factory, final InputStream inputStream) { _factory = factory; _reader = new BitStream(inputStream); }