1 package org
.spearce
.jgit
.lib
;
3 import java
.io
.BufferedReader
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
6 import java
.io
.InputStreamReader
;
7 import java
.io
.UnsupportedEncodingException
;
8 import java
.util
.zip
.InflaterInputStream
;
10 public class ObjectReader
{
11 private static final int TYPESZ
= 16;
13 private final ObjectId objectId
;
15 private final String objectType
;
17 private final int objectSize
;
19 private InflaterInputStream inflater
;
21 public ObjectReader(final ObjectId id
, final InputStream src
)
24 inflater
= new InflaterInputStream(src
);
26 final StringBuffer tempType
= new StringBuffer(TYPESZ
);
35 if (c
< 'a' || c
> 'z' || tempType
.length() >= 16) {
36 throw new CorruptObjectException(id
, "bad type in header");
38 tempType
.append((char) c
);
40 objectType
= tempType
.toString();
47 if (c
< '0' || c
> '9') {
48 throw new CorruptObjectException(id
, "bad length in header");
53 objectSize
= tempSize
;
56 public ObjectId
getId() {
60 public String
getType() {
64 public int getSize() {
68 public InputStream
getInputStream() {
69 if (inflater
== null) {
70 throw new IllegalStateException("Already closed.");
75 public BufferedReader
getBufferedReader()
76 throws UnsupportedEncodingException
{
77 return new BufferedReader(new InputStreamReader(getInputStream(),
81 public void close() throws IOException
{
82 if (inflater
!= null) {