2
This code is derived from jgit (http://eclipse.org/jgit).
3
Copyright owners are documented in jgit's IP log.
5
This program and the accompanying materials are made available
6
under the terms of the Eclipse Distribution License v1.0 which
7
accompanies this distribution, is reproduced below, and is
8
available at http://www.eclipse.org/org/documents/edl-v10.php
12
Redistribution and use in source and binary forms, with or
13
without modification, are permitted provided that the following
16
- Redistributions of source code must retain the above copyright
17
notice, this list of conditions and the following disclaimer.
19
- Redistributions in binary form must reproduce the above
20
copyright notice, this list of conditions and the following
21
disclaimer in the documentation and/or other materials provided
22
with the distribution.
24
- Neither the name of the Eclipse Foundation, Inc. nor the
25
names of its contributors may be used to endorse or promote
26
products derived from this software without specific prior
29
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30
CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
51
/// Stream of data coming from an object loaded by
52
/// <see cref="ObjectLoader">ObjectLoader</see>
55
public abstract class ObjectStream : InputStream
58
/// Git object type, see
59
/// <see cref="Constants">Constants</see>
62
public abstract int GetType();
64
/// <returns>total size of object in bytes</returns>
65
public abstract long GetSize();
67
/// <summary>Simple stream around the cached byte array created by a loader.</summary>
69
/// Simple stream around the cached byte array created by a loader.
71
/// ObjectLoader implementations can use this stream type when the object's
72
/// content is small enough to be accessed as a single byte array, but the
73
/// application has still requested it in stream format.
75
public class SmallStream : ObjectStream
77
private readonly int type;
79
private readonly byte[] data;
85
/// <summary>Create the stream from an existing loader's cached bytes.</summary>
86
/// <remarks>Create the stream from an existing loader's cached bytes.</remarks>
87
/// <param name="loader">the loader.</param>
88
public SmallStream(ObjectLoader loader) : this(loader.GetType(), loader.GetCachedBytes
93
/// <summary>Create the stream from an existing byte array and type.</summary>
94
/// <remarks>Create the stream from an existing byte array and type.</remarks>
95
/// <param name="type">the type constant for the object.</param>
96
/// <param name="data">the fully inflated content of the object.</param>
97
public SmallStream(int type, byte[] data)
103
public override int GetType()
108
public override long GetSize()
113
public override int Available()
115
return data.Length - ptr;
118
public override long Skip(long n)
120
int s = (int)Math.Min(Available(), Math.Max(0, n));
125
public override int Read()
127
if (ptr == data.Length)
131
return data[ptr++] & unchecked((int)(0xff));
134
public override int Read(byte[] b, int off, int len)
136
if (ptr == data.Length)
140
int n = Math.Min(Available(), len);
141
System.Array.Copy(data, ptr, b, off, n);
146
public override bool MarkSupported()
151
public override void Mark(int readlimit)
156
public override void Reset()
162
/// <summary>Simple filter stream around another stream.</summary>
164
/// Simple filter stream around another stream.
166
/// ObjectLoader implementations can use this stream type when the object's
167
/// content is available from a standard InputStream.
169
public class Filter : ObjectStream
171
private readonly int type;
173
private readonly long size;
175
private readonly InputStream @in;
177
/// <summary>Create a filter stream for an object.</summary>
178
/// <remarks>Create a filter stream for an object.</remarks>
179
/// <param name="type">the type of the object.</param>
180
/// <param name="size">total size of the object, in bytes.</param>
181
/// <param name="in">
182
/// stream the object's raw data is available from. This
183
/// stream should be buffered with some reasonable amount of
186
public Filter(int type, long size, InputStream @in)
193
public override int GetType()
198
public override long GetSize()
203
/// <exception cref="System.IO.IOException"></exception>
204
public override int Available()
206
return @in.Available();
209
/// <exception cref="System.IO.IOException"></exception>
210
public override long Skip(long n)
215
/// <exception cref="System.IO.IOException"></exception>
216
public override int Read()
221
/// <exception cref="System.IO.IOException"></exception>
222
public override int Read(byte[] b, int off, int len)
224
return @in.Read(b, off, len);
227
public override bool MarkSupported()
229
return @in.MarkSupported();
232
public override void Mark(int readlimit)
237
/// <exception cref="System.IO.IOException"></exception>
238
public override void Reset()
243
/// <exception cref="System.IO.IOException"></exception>
244
public override void Close()