2 * Copyright (C) 2006 Shawn Pearce <spearce@spearce.org>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License, version 2.1, as published by the Free Software Foundation.
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, write to the Free Software
15 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301
17 package org
.spearce
.jgit
.lib
;
19 import java
.nio
.ByteBuffer
;
20 import java
.util
.zip
.DataFormatException
;
21 import java
.util
.zip
.Inflater
;
23 public final class ByteBufferWindow
extends ByteWindow
{
24 private final ByteBuffer buffer
;
26 public ByteBufferWindow(final WindowProvider o
, final int d
,
32 public final int copy(final int p
, final byte[] b
, final int o
, int n
) {
33 final ByteBuffer s
= buffer
.slice();
35 n
= Math
.min(s
.remaining(), n
);
40 public int inflate(final int pos
, final byte[] b
, int o
, final Inflater inf
)
41 throws DataFormatException
{
42 final byte[] tmp
= new byte[512];
43 final ByteBuffer s
= buffer
.slice();
45 while (s
.remaining() > 0 && !inf
.finished()) {
46 if (inf
.needsInput()) {
47 final int n
= Math
.min(s
.remaining(), tmp
.length
);
49 inf
.setInput(tmp
, 0, n
);
51 o
+= inf
.inflate(b
, o
, b
.length
- o
);
53 while (!inf
.finished() && !inf
.needsInput())
54 o
+= inf
.inflate(b
, o
, b
.length
- o
);
59 return buffer
.capacity();