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.

SimpleDataInput.java 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * Copyright (C) 2012, Google Inc. 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.DataInput;
  12. import java.io.IOException;
  13. import java.io.InputStream;
  14. import org.eclipse.jgit.util.IO;
  15. import org.eclipse.jgit.util.NB;
  16. /**
  17. * An implementation of DataInput that only handles readInt() and readLong()
  18. * using the Git conversion utilities for network byte order handling. This is
  19. * needed to read {@link com.googlecode.javaewah.EWAHCompressedBitmap}s.
  20. */
  21. class SimpleDataInput implements DataInput {
  22. private final InputStream fd;
  23. private final byte[] buf = new byte[8];
  24. SimpleDataInput(InputStream fd) {
  25. this.fd = fd;
  26. }
  27. /** {@inheritDoc} */
  28. @Override
  29. public int readInt() throws IOException {
  30. readFully(buf, 0, 4);
  31. return NB.decodeInt32(buf, 0);
  32. }
  33. /** {@inheritDoc} */
  34. @Override
  35. public long readLong() throws IOException {
  36. readFully(buf, 0, 8);
  37. return NB.decodeInt64(buf, 0);
  38. }
  39. /**
  40. * Read unsigned int
  41. *
  42. * @return a long.
  43. * @throws java.io.IOException
  44. * if any.
  45. */
  46. public long readUnsignedInt() throws IOException {
  47. readFully(buf, 0, 4);
  48. return NB.decodeUInt32(buf, 0);
  49. }
  50. /** {@inheritDoc} */
  51. @Override
  52. public void readFully(byte[] b) throws IOException {
  53. readFully(b, 0, b.length);
  54. }
  55. /** {@inheritDoc} */
  56. @Override
  57. public void readFully(byte[] b, int off, int len) throws IOException {
  58. IO.readFully(fd, b, off, len);
  59. }
  60. /** {@inheritDoc} */
  61. @Override
  62. public int skipBytes(int n) throws IOException {
  63. throw new UnsupportedOperationException();
  64. }
  65. /** {@inheritDoc} */
  66. @Override
  67. public boolean readBoolean() throws IOException {
  68. throw new UnsupportedOperationException();
  69. }
  70. /** {@inheritDoc} */
  71. @Override
  72. public byte readByte() throws IOException {
  73. throw new UnsupportedOperationException();
  74. }
  75. /** {@inheritDoc} */
  76. @Override
  77. public int readUnsignedByte() throws IOException {
  78. throw new UnsupportedOperationException();
  79. }
  80. /** {@inheritDoc} */
  81. @Override
  82. public short readShort() throws IOException {
  83. throw new UnsupportedOperationException();
  84. }
  85. /** {@inheritDoc} */
  86. @Override
  87. public int readUnsignedShort() throws IOException {
  88. throw new UnsupportedOperationException();
  89. }
  90. /** {@inheritDoc} */
  91. @Override
  92. public char readChar() throws IOException {
  93. throw new UnsupportedOperationException();
  94. }
  95. /** {@inheritDoc} */
  96. @Override
  97. public float readFloat() throws IOException {
  98. throw new UnsupportedOperationException();
  99. }
  100. /** {@inheritDoc} */
  101. @Override
  102. public double readDouble() throws IOException {
  103. throw new UnsupportedOperationException();
  104. }
  105. /** {@inheritDoc} */
  106. @Override
  107. public String readLine() throws IOException {
  108. throw new UnsupportedOperationException();
  109. }
  110. /** {@inheritDoc} */
  111. @Override
  112. public String readUTF() throws IOException {
  113. throw new UnsupportedOperationException();
  114. }
  115. }