1 |
/* |
/* |
2 |
* $Id$ |
* ByteArrayRequestBodyWriter.java |
3 |
* Copyright (C) 2004 The Free Software Foundation |
* Copyright (C) 2004 The Free Software Foundation |
4 |
* |
* |
5 |
* This file is part of GNU inetlib, a library. |
* This file is part of GNU inetlib, a library. |
44 |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
* @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> |
45 |
*/ |
*/ |
46 |
public class ByteArrayRequestBodyWriter |
public class ByteArrayRequestBodyWriter |
47 |
implements RequestBodyWriter |
implements RequestBodyWriter |
48 |
{ |
{ |
49 |
|
|
50 |
/** |
/** |
62 |
* content. |
* content. |
63 |
* @param content the content buffer |
* @param content the content buffer |
64 |
*/ |
*/ |
65 |
public ByteArrayRequestBodyWriter (byte[] content) |
public ByteArrayRequestBodyWriter(byte[] content) |
66 |
{ |
{ |
67 |
this.content = content; |
this.content = content; |
68 |
pos = 0; |
pos = 0; |
72 |
* Returns the total number of bytes that will be written in a single pass |
* Returns the total number of bytes that will be written in a single pass |
73 |
* by this writer. |
* by this writer. |
74 |
*/ |
*/ |
75 |
public int getContentLength () |
public int getContentLength() |
76 |
{ |
{ |
77 |
return content.length; |
return content.length; |
78 |
} |
} |
81 |
* Initialises the writer. |
* Initialises the writer. |
82 |
* This will be called before each pass. |
* This will be called before each pass. |
83 |
*/ |
*/ |
84 |
public void reset () |
public void reset() |
85 |
{ |
{ |
86 |
pos = 0; |
pos = 0; |
87 |
} |
} |
91 |
* @param buffer the content buffer |
* @param buffer the content buffer |
92 |
* @return the number of bytes written |
* @return the number of bytes written |
93 |
*/ |
*/ |
94 |
public int write (byte[] buffer) |
public int write(byte[] buffer) |
95 |
{ |
{ |
96 |
int len = content.length - pos; |
int len = content.length - pos; |
97 |
len = (buffer.length < len) ? buffer.length : len; |
len = (buffer.length < len) ? buffer.length : len; |
98 |
if (len > -1) |
if (len > -1) |
99 |
{ |
{ |
100 |
System.arraycopy (content, pos, buffer, 0, len); |
System.arraycopy(content, pos, buffer, 0, len); |
101 |
pos += len; |
pos += len; |
102 |
} |
} |
103 |
return len; |
return len; |
104 |
} |
} |
105 |
|
|
106 |
} |
} |
107 |
|
|