1 package org
.spearce
.jgit
.lib
;
3 import java
.io
.ByteArrayOutputStream
;
4 import java
.io
.IOException
;
5 import java
.io
.InputStream
;
6 import java
.util
.ArrayList
;
9 public class Tree
implements Treeish
{
10 private final ObjectDatabase objdb
;
12 private final ObjectId treeId
;
14 private final List entries
;
16 public Tree(final ObjectDatabase db
, final ObjectId id
, final InputStream is
)
21 final ArrayList tempEnts
= new ArrayList();
25 final ByteArrayOutputStream nameBuf
;
33 if (c
< '0' || c
> '7') {
34 throw new CorruptObjectException("Invalid tree entry in " + id
);
42 if (c
< '0' || c
> '7') {
43 throw new CorruptObjectException("Invalid tree entry in "
50 nameBuf
= new ByteArrayOutputStream(128);
54 throw new CorruptObjectException("Invalid tree entry in "
65 while ((c
= is
.read(entId
, entIdLen
, entId
.length
- entIdLen
)) > 0) {
68 if (entIdLen
!= entId
.length
) {
69 throw new CorruptObjectException("Invalid tree entry in " + id
);
72 tempEnts
.add(new Entry(mode
, new String(nameBuf
.toByteArray(),
73 "UTF-8"), new ObjectId(entId
)));
79 public ObjectId
getTreeId() {
83 public List
getTreeEntries() {
88 private final int mode
;
90 private final String name
;
92 private final ObjectId id
;
96 private Entry(final int mode
, final String name
, final ObjectId id
) {
102 public boolean isTree() {
103 return (getMode() & 040000) != 0;
106 public boolean isSymlink() {
107 return (getMode() & 020000) != 0;
110 public boolean isExecutable() {
111 return (getMode() & 0100) != 0;
114 public String
getName() {
118 public int getMode() {
122 public ObjectId
getId() {
126 public Tree
getTree() throws IOException
{
127 if (treeObj
== null) {
128 treeObj
= objdb
.openTree(getId());
133 public ObjectReader
openBlob() throws IOException
{
134 return objdb
.openBlob(getId());
137 public String
toString() {
138 final StringBuffer r
= new StringBuffer();
139 final String modeStr
= Integer
.toString(getMode(), 8);
144 } else if (isSymlink()) {
146 } else if (isExecutable()) {
152 if (modeStr
.length() == 5) {