Parse a PDB file and return a datastructure implementing
PDBStructure interface.

@param buf  a BufferedReader object
@return the Structure object
@throws IOException ...
180025
public  Structure parsePDBFile(BufferedReader buf)
			throws IOException
			{
		// set the correct max values for parsing...
		loadMaxAtoms = params.getMaxAtoms();
		atomCAThreshold = params.getAtomCaThreshold();


		// (re)set structure

		allModels = new ArrayList<>();
		structure     = new StructureImpl() ;
		currentModel  = null;
		currentChain  = null;
		currentGroup  = null;
		// we initialise to true since at the beginning of the file we are always starting a new molecule
		startOfMolecule = true;
		startOfModel = true;

		seqResChains  = new ArrayList<Chain>();
		siteMap = new LinkedHashMap<String, Site>();
		pdbHeader     = new PDBHeader();
		connects      = new ArrayList<Map<String,Integer>>();
		previousContinuationField = "";
		continuationField = "";
		continuationString = "";
		current_compound = null;
		sourceLines.clear();
		compndLines.clear();
		isLastCompndLine = false;
		isLastSourceLine = false;
		prevMolId = -1;
		entities.clear();
		helixList.clear();
		strandList.clear();
		turnList.clear();
		lengthCheck = -1;
		atomCount = 0;
		atomOverflow = false;
		linkRecords = new ArrayList<LinkRecord>();
		siteToResidueMap.clear();

		blankChainIdsPresent = false;

		parseCAonly = params.isParseCAOnly();

		String line = null;

		while ((line = buf.readLine()) != null) {

			// ignore empty lines
			if ( line.equals("") ||
					(line.equals(NEWLINE))){
				continue;
			}


			// ignore short TER and END lines
			if ( line.startsWith("END")) {
				continue;
			}

			if ( line.length() < 6 && !line.startsWith("TER")) {
				logger.info("Found line length below 6. Ignoring it, line: >" + line +"<" );
				continue;
			}

			String recordName = null;
			if (line.length()<6)
				recordName = line.trim();
			else
				recordName = line.substring (0, 6).trim ();

			try {
				if (recordName.equals("ATOM"))
					pdb_ATOM_Handler(line);
				else if (recordName.equals("SEQRES"))
					pdb_SEQRES_Handler(line);
				else if (recordName.equals("HETATM"))
					pdb_ATOM_Handler(line);
				else if (recordName.equals("MODEL"))
					pdb_MODEL_Handler(line);
				else if (recordName.equals("TER"))
					pdb_TER_Handler();
				else if (recordName.equals("HEADER"))
					pdb_HEADER_Handler(line);
				else if (recordName.equals("AUTHOR"))
					pdb_AUTHOR_Handler(line);
				else if (recordName.equals("TITLE"))
					pdb_TITLE_Handler(line);
				else if (recordName.equals("SOURCE"))
					sourceLines.add(line); //pdb_SOURCE_Handler
				else if (recordName.equals("COMPND"))
					compndLines.add(line); //pdb_COMPND_Handler
				else if (recordName.equals("JRNL"))
					pdb_JRNL_Handler(line);
				else if (recordName.equals("EXPDTA"))
					pdb_EXPDTA_Handler(line);
				else if (recordName.equals("CRYST1"))
					pdb_CRYST1_Handler(line);
				else if (recordName.startsWith("MTRIX"))
					pdb_MTRIXn_Handler(line);
				else if (recordName.equals("REMARK"))
					pdb_REMARK_Handler(line);
				else if (recordName.equals("CONECT"))
					pdb_CONECT_Handler(line);
				else if (recordName.equals("REVDAT"))
					pdb_REVDAT_Handler(line);
				else if (recordName.equals("DBREF"))
					pdb_DBREF_Handler(line);
				else if (recordName.equals("SITE"))
					pdb_SITE_Handler(line);
				else if (recordName.equals("SSBOND"))
					pdb_SSBOND_Handler(line);
				else if (recordName.equals("LINK"))
					pdb_LINK_Handler(line);
				else if ( params.isParseSecStruc()) {
					if ( recordName.equals("HELIX") ) pdb_HELIX_Handler (  line ) ;
					else if (recordName.equals("SHEET")) pdb_SHEET_Handler(line ) ;
					else if (recordName.equals("TURN")) pdb_TURN_Handler(   line ) ;
				}
			} catch (StringIndexOutOfBoundsException | NullPointerException ex) {
				logger.info("Unable to parse [" + line + "]");
			}
		}

		makeCompounds(compndLines, sourceLines);

		triggerEndFileChecks();

		if (params.shouldCreateAtomBonds()) {
			formBonds();
		}

		if ( params.shouldCreateAtomCharges()) {
			addCharges();
		}

		if ( params.isParseSecStruc() && !params.isHeaderOnly())
			setSecStruc();

		// Now correct the alternate location group
		StructureTools.cleanUpAltLocs(structure);

		return structure;

			}
697171
public static String readDbfInfo(File dbf) {
        try (DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(dbf)))) {
            DbfHeader header = DbfHeader.read(in);
            StringBuilder sb = new StringBuilder(512);
            sb.append("Created at: ")
                    .append(header.getYear()).append('-').append(header.getMonth())
                    .append('-').append(header.getDay()).append('\n')
                    .append("Total records: ").append(header.getNumberOfRecords()).append('\n')
                    .append("Header length: ").append(header.getHeaderLength()).append('\n')
                    .append("Columns: ").append('\n');

            sb.append("  ").append(rightPad("#", INDEX_WIDTH, ' '))
                    .append(rightPad("Name", NAME_WIDTH, ' '))
                    .append(rightPad("Type", TYPE_WIDTH, ' '))
                    .append(rightPad("Length", LENGTH_WIDTH, ' '))
                    .append(rightPad("Decimal", DECIMAL_WIDTH, ' '))
                    .append('\n');

            int totalWidth = INDEX_WIDTH + NAME_WIDTH + TYPE_WIDTH + LENGTH_WIDTH + DECIMAL_WIDTH + 2;
            for (int i = 0; i < totalWidth; i++) sb.append('-');

            for (int i = 0; i < header.getFieldsCount(); i++) {
                DbfField field = header.getField(i);
                sb.append('\n')
                        .append("  ").append(rightPad(String.valueOf(i), INDEX_WIDTH, ' '))
                        .append(rightPad(field.getName(), NAME_WIDTH, ' '))
                        .append(rightPad(String.valueOf((char) field.getDataType().byteValue), TYPE_WIDTH, ' '))
                        .append(rightPad(String.valueOf(field.getFieldLength()), LENGTH_WIDTH, ' '))
                        .append(rightPad(String.valueOf(field.getDecimalCount()), DECIMAL_WIDTH, ' '));
            }

            return sb.toString();
        } catch (IOException e) {
            throw new DbfException("Cannot read header of .dbf file " + dbf, e);
        }
    }
488447
static UTF8StreamJsonParser newJsonParser(InputStream in, byte[] buf,
            int offset, int limit, boolean bufferRecyclable, IOContext context)
            throws IOException
    {
        return new UTF8StreamJsonParser(context,
                DEFAULT_JSON_FACTORY.getParserFeatures(), in,
                DEFAULT_JSON_FACTORY.getCodec(),
                DEFAULT_JSON_FACTORY.getRootByteSymbols().makeChild(1),
                buf, offset, limit, bufferRecyclable);
    }
72972
def parse(self, buf):
        
        self._tokenizer = tokenize_asdl(buf)
        self._advance()
        return self._parse_module()
573554
public int read(char []buf, int offset, int length)
    throws IOException
  {
    for (int i = 0; i < length; i++) {
      int ch = is.read();

      if (ch < 0)
        return i > 0 ? i : -1;
      else {
        buf[offset + i] = (char) ch;
      }
    }
      
    return length;
  }
51280
function parseJSON(buf, cb) {
    try {
        cb(null, JSON.parse(buf));
    } catch (err) {
        return cb(err);
    }
}
1274216
public static <T extends Appendable> T byteToHexString(T buf, int value) {
        try {
            buf.append(byteToHexString(value));
        } catch (IOException e) {
            PlatformDependent.throwException(e);
        }
        return buf;
    }
400616
public synchronized long readFromEnd(final long datalen, final ByteBuffer buf) {
		if (!validState) {
			throw new InvalidStateException();
		}
		final long size = size();
		final long offset = (size - HEADER_LEN - datalen - FOOTER_LEN);
		return read(offset, buf);
	}
615965
def parse_protobuf(self, proto_type):
        """"""
        if 'protobuf' not in self.environ.get('CONTENT_TYPE', ''):
            raise BadRequest('Not a Protobuf request')

        obj = proto_type()
        try:
            obj.ParseFromString(self.data)
        except Exception:
            raise BadRequest("Unable to parse Protobuf request")

        # Fail if not all required fields are set
        if self.protobuf_check_initialization and not obj.IsInitialized():
            raise BadRequest("Partial Protobuf request")

        return obj
499466
private void fillBuf() throws IOException {
		int result = in.read(buf, 0, buf.length);
		if (result == -1) {
			throw new EOFException();
		}
		pos = 0;
		end = result;
	}
778232
@Override
  public synchronized int read(byte[] buf, int offset, int length) throws IOException {
    if (buf == null) {
      throw new IllegalArgumentException("buf must not be null");
    }

    if (!(offset >= 0 && length > 0 && offset < buf.length && length <= (buf.length - offset))) {
      throw new IllegalArgumentException("invalid offset and lengeth");
    }

    // Return early if closed is true; throw the saved exception if needed.
    if (closed) {
      if (exception != null) {
        throw exception;
      }
      return -1;
    }

    // Check if there is already a chunk that hasn't been exhausted; call take() if not.
    if (currentChunk == null) {
      if (currentChunkReadPos != -1) {
        throw new IllegalStateException("currentChunk is null but currentChunkReadPos is not -1");
      }

      byte[] next = null;
      try {
        if (timeoutMillis >= 0) {
          next = queue.poll(timeoutMillis, TimeUnit.MILLISECONDS);
        } else {
          next = queue.take();
        }
      } catch (InterruptedException e) {
        // Unlikely to happen.
        throw new AssertionError(e);
      }
      if (next == null) {
        closed = true;
        SocketTimeoutException timeoutException = new SocketTimeoutException();

        if (exception == null) {
          exception = timeoutException;
          // It is still possible that an endOffer(Exception) races and set exception at this point,
          // but timeoutException is still being thrown, and it's ok for subsequent reads to
          // throw the exception set by endOffer(Exception).
        }

        throw timeoutException;
      }

      // If it's the end marker, acknowledge that so that the buffer will mark itself as closed
      // for reading.
      if (next == CLOSED) {
        closed = true;
        if (exception != null) {
          throw exception;
        }
        return -1;
      }
      currentChunk = next;
      currentChunkReadPos = 0;
    }

    int available = currentChunk.length - currentChunkReadPos;
    if (length < available) {
      // Copy from the currentChunk.
      System.arraycopy(currentChunk, currentChunkReadPos, buf, offset, length);
      currentChunkReadPos += length;
      return length;
    } else {
      // Copy the entire currentChunk.
      System.arraycopy(currentChunk, currentChunkReadPos, buf, offset, available);
      currentChunk = null;
      currentChunkReadPos = -1;
      return available;
    }
  }
419620
public static boolean isText(ByteBuf buf, Charset charset) {
        return isText(buf, buf.readerIndex(), buf.readableBytes(), charset);
    }
561223
public void flattenToBuffer(ByteBuffer buf) {
        buf.put(INCOMPLETE_ENCODING_FROM_JAVA); // encoding version
        buf.put((byte)1); // owns_loops_
        buf.put((byte)(m_loops.size() > 1 ? 1 : 0)); // has_holes_
        buf.putInt(m_loops.size());
        int depth = 0;
        for (List<XYZPoint> loop : m_loops) {
            flattenLoopToBuffer(loop, depth, buf);
            depth = 1;
        }
        flattenEmptyBoundToBuffer(buf);
    }
87304
@Nullable
	@Contract(pure = true)
	public ByteBuf peekBuf() {
		return hasRemaining() ? bufs[first] : null;
	}
1005155
private Collection<ByteBuf> parseJsonFrame(Channel channel, ByteBuf channelBuffer) throws IOException {
        sequenceNum = channelBuffer.readUnsignedInt();
        LOG.trace("Received sequence number {}", sequenceNum);

        final int jsonLength = Ints.saturatedCast(channelBuffer.readUnsignedInt());

        final ByteBuf buffer = channelBuffer.readBytes(jsonLength);
        sendACK(channel);

        return Collections.singleton(buffer);
    }
1282250
public static HashMap<String, String> parseDirectives(byte[] buf)
            throws SaslException {
        HashMap<String, String> map = new HashMap<>();
        boolean gettingKey = true;
        boolean gettingQuotedValue = false;
        boolean expectSeparator = false;
        byte bch;

        ByteArrayOutputStream key = new ByteArrayOutputStream(10);
        ByteArrayOutputStream value = new ByteArrayOutputStream(10);

        int i = skipLws(buf, 0);
        while (i < buf.length) {
            bch = buf[i];

            if (gettingKey) {
                if (bch == ',') {
                    if (key.size() != 0) {
                        throw new SaslException("Directive key contains a ',':"
                                + key);
                    }

                    // Empty element, skip separator and lws
                    i = skipLws(buf, i + 1);
                } else if (bch == '=') {
                    if (key.size() == 0) {
                        throw new SaslException("Empty directive key");
                    }

                    gettingKey = false; // Termination of key
                    i = skipLws(buf, i + 1); // Skip to next non whitespace

                    // Check whether value is quoted
                    if (i < buf.length) {
                        if (buf[i] == '"') {
                            gettingQuotedValue = true;
                            ++i; // Skip quote
                        }
                    } else {
                        throw new SaslException("Valueless directive found: "
                                + key.toString());
                    }
                } else if (isLws(bch)) {
                    // LWS that occurs after key
                    i = skipLws(buf, i + 1);

                    // Expecting '='
                    if (i < buf.length) {
                        if (buf[i] != '=') {
                            throw new SaslException("'=' expected after key: "
                                    + key.toString());
                        }
                    } else {
                        throw new SaslException("'=' expected after key: "
                                + key.toString());
                    }
                } else {
                    key.write(bch); // Append to key
                    ++i; // Advance
                }
            } else if (gettingQuotedValue) {
                // Getting a quoted value
                if (bch == '\\') {
                    // quoted-pair = "\" CHAR ==> CHAR
                    ++i; // Skip escape
                    if (i < buf.length) {
                        value.write(buf[i]);
                        ++i; // Advance
                    } else {
                        // Trailing escape in a quoted value
                        throw new SaslException(
                                "Unmatched quote found for directive: "
                                        + key.toString() + " with value: "
                                        + value.toString());
                    }
                } else if (bch == '"') {
                    // closing quote
                    ++i; // Skip closing quote
                    gettingQuotedValue = false;
                    expectSeparator = true;
                } else {
                    value.write(bch);
                    ++i; // Advance
                }
            } else if (isLws(bch) || bch == ',') {
                // Value terminated
                extractDirective(map, key.toString(), value.toString());
                key.reset();
                value.reset();
                gettingKey = true;
                gettingQuotedValue = expectSeparator = false;
                i = skipLws(buf, i + 1); // Skip separator and LWS
            } else if (expectSeparator) {
                throw new SaslException(
                        "Expecting comma or linear whitespace after quoted string: \""
                                + value.toString() + "\"");
            } else {
                value.write(bch); // Unquoted value
                ++i; // Advance
            }
        }

        if (gettingQuotedValue) {
            throw new SaslException("Unmatched quote found for directive: "
                    + key.toString() + " with value: " + value.toString());
        }

        // Get last pair
        if (key.size() > 0) {
            extractDirective(map, key.toString(), value.toString());
        }

        return map;
    }
1024048
def read_from_string(buf)
      @lexer.stream_stash([FileIO.new(StringIO.new(buf), "-")])
      parse.each do |toplevel_ast|
        @gen.emit_toplevel(toplevel_ast)
      end
      @lexer.stream_unstash
    end