You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

XInputStream.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (C) 2006-2008, Shawn O. Pearce <spearce@spearce.org> and others
  3. *
  4. * This program and the accompanying materials are made available under the
  5. * terms of the Eclipse Distribution License v. 1.0 which is available at
  6. * https://www.eclipse.org/org/documents/edl-v10.php.
  7. *
  8. * SPDX-License-Identifier: BSD-3-Clause
  9. */
  10. package org.eclipse.jgit.internal.storage.file;
  11. import java.io.BufferedInputStream;
  12. import java.io.EOFException;
  13. import java.io.IOException;
  14. import java.io.InputStream;
  15. import org.eclipse.jgit.util.NB;
  16. class XInputStream extends BufferedInputStream {
  17. private final byte[] intbuf = new byte[8];
  18. XInputStream(InputStream s) {
  19. super(s);
  20. }
  21. synchronized byte[] readFully(final int len) throws IOException {
  22. final byte[] b = new byte[len];
  23. readFully(b, 0, len);
  24. return b;
  25. }
  26. synchronized void readFully(byte[] b, int o, int len)
  27. throws IOException {
  28. int r;
  29. while (len > 0 && (r = read(b, o, len)) > 0) {
  30. o += r;
  31. len -= r;
  32. }
  33. if (len > 0)
  34. throw new EOFException();
  35. }
  36. int readUInt8() throws IOException {
  37. final int r = read();
  38. if (r < 0)
  39. throw new EOFException();
  40. return r;
  41. }
  42. long readUInt32() throws IOException {
  43. readFully(intbuf, 0, 4);
  44. return NB.decodeUInt32(intbuf, 0);
  45. }
  46. }