2 * Copyright (C) 2008 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 General Public
6 * License, version 2, 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 * General Public License for more details.
13 * You should have received a copy of the GNU 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
.transport
;
19 import java
.io
.IOException
;
20 import java
.io
.OutputStream
;
22 import org
.spearce
.jgit
.lib
.Constants
;
25 private final OutputStream out
;
27 private final byte[] lenbuffer
;
29 PacketLineOut(final OutputStream i
) {
31 lenbuffer
= new byte[4];
34 void writeString(final String s
) throws IOException
{
35 writePacket(Constants
.encodeASCII(s
));
38 void writePacket(final byte[] packet
) throws IOException
{
39 writeLength(packet
.length
+ 4);
43 void end() throws IOException
{
48 void flush() throws IOException
{
52 private static final byte[] hexchar
= { '0', '1', '2', '3', '4', '5', '6',
53 '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
55 private void writeLength(int w
) throws IOException
{
57 while (o
>= 0 && w
!= 0) {
58 lenbuffer
[o
--] = hexchar
[w
& 0xf];
63 out
.write(lenbuffer
, 0, 4);