static byte [] de.alysis.r.submit.model.SubmitUtils.getInputStreamAsByteArray InputStream  stream,
int  length
throws IOException [static, protected]
 

Returns the given input stream's contents as a byte array.

If a length is specified (ie. if length != -1), only length bytes are returned. Otherwise all bytes in the stream are returned. Note this doesn't close the stream.

Exceptions:
IOException if a problem occured reading the stream.
00050                                                        {
00051                 byte[] contents;
00052                 if (length == -1) {
00053                         contents = new byte[0];
00054                         int contentsLength = 0;
00055                         int bytesRead = -1;
00056                         do {
00057                                 int available = stream.available();
00058 
00059                                 // resize contents if needed
00060                                 if (contentsLength + available > contents.length) {
00061                                         System.arraycopy(contents, 0,
00062                                                         contents = new byte[contentsLength + available], 0,
00063                                                         contentsLength);
00064                                 }
00065 
00066                                 // read as many bytes as possible
00067                                 bytesRead = stream.read(contents, contentsLength, available);
00068 
00069                                 if (bytesRead > 0) {
00070                                         // remember length of contents
00071                                         contentsLength += bytesRead;
00072                                 }
00073                         } while (bytesRead > 0);
00074 
00075                         // resize contents if necessary
00076                         if (contentsLength < contents.length) {
00077                                 System.arraycopy(contents, 0,
00078                                                 contents = new byte[contentsLength], 0, contentsLength);
00079                         }
00080                 } else {
00081                         contents = new byte[length];
00082                         int len = 0;
00083                         int readSize = 0;
00084                         while ((readSize != -1) && (len != length)) {
00085                                 // See PR 1FMS89U
00086                                 // We record first the read size. In this
00087                                 // case len is the actual read size.
00088                                 len += readSize;
00089                                 readSize = stream.read(contents, len, length - len);
00090                         }
00091                 }
00092 
00093                 return contents;
00094         }


Generated on Mon Jun 26 18:45:59 2006 for RSubmit by  doxygen 1.4.6