/[classpath]/inetlib/source/gnu/inet/http/ByteArrayResponseBodyReader.java
ViewVC logotype

Diff of /inetlib/source/gnu/inet/http/ByteArrayResponseBodyReader.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by dog, Thu Oct 21 15:21:55 2004 UTC revision 1.3 by dog, Thu Nov 25 22:15:05 2004 UTC
# Line 1  Line 1 
1  /*  /*
2   * $Id$   * ByteArrayResponseBodyReader.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.
# Line 44  package gnu.inet.http; Line 44  package gnu.inet.http;
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 ByteArrayResponseBodyReader  public class ByteArrayResponseBodyReader
47  implements ResponseBodyReader    implements ResponseBodyReader
48  {  {
49    
50    /**    /**
# Line 65  implements ResponseBodyReader Line 65  implements ResponseBodyReader
65    /**    /**
66     * Constructs a new byte array response body reader.     * Constructs a new byte array response body reader.
67     */     */
68    public ByteArrayResponseBodyReader ()    public ByteArrayResponseBodyReader()
69    {    {
70      this (4096);      this(4096);
71    }    }
72        
73    /**    /**
# Line 75  implements ResponseBodyReader Line 75  implements ResponseBodyReader
75     * initial buffer size.     * initial buffer size.
76     * @param size the initial buffer size     * @param size the initial buffer size
77     */     */
78    public ByteArrayResponseBodyReader (int size)    public ByteArrayResponseBodyReader(int size)
79    {    {
80      content = new byte[size];      content = new byte[size];
81      pos = len = 0;      pos = len = 0;
# Line 84  implements ResponseBodyReader Line 84  implements ResponseBodyReader
84    /**    /**
85     * This reader accepts all responses.     * This reader accepts all responses.
86     */     */
87    public boolean accept (Request request, Response response)    public boolean accept(Request request, Response response)
88    {    {
89      return true;      return true;
90    }    }
91    
92    public void read (byte[] buffer, int offset, int length)    public void read(byte[] buffer, int offset, int length)
93    {    {
94      int l = length - offset;      int l = length - offset;
95      if (pos + l > content.length)      if (pos + l > content.length)
96        {        {
97          byte[] tmp = new byte[content.length * 2];          byte[] tmp = new byte[content.length * 2];
98          System.arraycopy (content, 0, tmp, 0, pos);          System.arraycopy(content, 0, tmp, 0, pos);
99          content = tmp;          content = tmp;
100        }        }
101      System.arraycopy (buffer, offset, content, pos, l);      System.arraycopy(buffer, offset, content, pos, l);
102      pos += l;      pos += l;
103      len = pos;      len = pos;
104    }    }
105    
106    public void close ()    public void close()
107    {    {
108      pos = 0;      pos = 0;
109    }    }
# Line 112  implements ResponseBodyReader Line 112  implements ResponseBodyReader
112     * Retrieves the content of this reader as a byte array.     * Retrieves the content of this reader as a byte array.
113     * The size of the returned array is the number of bytes read.     * The size of the returned array is the number of bytes read.
114     */     */
115    public byte[] toByteArray ()    public byte[] toByteArray()
116    {    {
117      byte[] ret = new byte[len];      byte[] ret = new byte[len];
118      System.arraycopy (content, 0, ret, 0, len);      System.arraycopy(content, 0, ret, 0, len);
119      return ret;      return ret;
120    }    }
121        
122  }  }
123    

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26