1069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/*
2069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $HeadURL: http://svn.apache.org/repos/asf/httpcomponents/httpcore/trunk/module-main/src/main/java/org/apache/http/impl/io/ContentLengthInputStream.java $
3069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Revision: 652091 $
4069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * $Date: 2008-04-29 13:41:07 -0700 (Tue, 29 Apr 2008) $
5069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
6069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
7069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Licensed to the Apache Software Foundation (ASF) under one
8069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * or more contributor license agreements.  See the NOTICE file
9069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * distributed with this work for additional information
10069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * regarding copyright ownership.  The ASF licenses this file
11069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * to you under the Apache License, Version 2.0 (the
12069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * "License"); you may not use this file except in compliance
13069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * with the License.  You may obtain a copy of the License at
14069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
15069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *   http://www.apache.org/licenses/LICENSE-2.0
16069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
17069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Unless required by applicable law or agreed to in writing,
18069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * software distributed under the License is distributed on an
19069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
20069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * KIND, either express or implied.  See the License for the
21069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * specific language governing permissions and limitations
22069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * under the License.
23069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * ====================================================================
24069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
25069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * This software consists of voluntary contributions made by many
26069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * individuals on behalf of the Apache Software Foundation.  For more
27069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * information on the Apache Software Foundation, please see
28069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <http://www.apache.org/>.
29069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
30069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
31069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
32069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpackage org.apache.http.impl.io;
33069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
34069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport java.io.IOException;
35069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport java.io.InputStream;
36069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
37069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectimport org.apache.http.io.SessionInputBuffer;
38069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
39069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project/**
40069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Stream that cuts off after a specified number of bytes.
41069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Note that this class NEVER closes the underlying stream, even when close
42069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * gets called.  Instead, it will read until the "end" of its chunking on
43069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * close, which allows for the seamless execution of subsequent HTTP 1.1
44069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * requests, while not requiring the client to remember to read the entire
45069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * contents of the response.
46069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
47069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p>Implementation note: Choices abound. One approach would pass
48069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * through the {@link InputStream#mark} and {@link InputStream#reset} calls to
49069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * the underlying stream.  That's tricky, though, because you then have to
50069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * start duplicating the work of keeping track of how much a reset rewinds.
51069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * Further, you have to watch out for the "readLimit", and since the semantics
52069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * for the readLimit leave room for differing implementations, you might get
53069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * into a lot of trouble.</p>
54069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
55069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p>Alternatively, you could make this class extend
56069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * {@link java.io.BufferedInputStream}
57069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * and then use the protected members of that class to avoid duplicated effort.
58069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * That solution has the side effect of adding yet another possible layer of
59069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * buffering.</p>
60069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
61069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * <p>Then, there is the simple choice, which this takes - simply don't
62069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * support {@link InputStream#mark} and {@link InputStream#reset}.  That choice
63069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * has the added benefit of keeping this class very simple.</p>
64069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
65069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author Ortwin Glueck
66069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author Eric Johnson
67069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @author <a href="mailto:mbowler@GargoyleSoftware.com">Mike Bowler</a>
68069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project *
69069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project * @since 4.0
70d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *
71d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath * @deprecated Please use {@link java.net.URL#openConnection} instead.
72d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *     Please visit <a href="http://android-developers.blogspot.com/2011/09/androids-http-clients.html">this webpage</a>
73d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath *     for further details.
74069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project */
75d42abb2fd917184764daf22f5f299e848b8701d7Narayan Kamath@Deprecated
76069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Projectpublic class ContentLengthInputStream extends InputStream {
77069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
78069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    private static final int BUFFER_SIZE = 2048;
79069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
80069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * The maximum number of bytes that can be read from the stream. Subsequent
81069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * read operations will return -1.
82069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
83069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    private long contentLength;
84069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
85069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /** The current position */
86069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    private long pos = 0;
87069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
88069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /** True if the stream is closed. */
89069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    private boolean closed = false;
90069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
91069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
92069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Wrapped input stream that all calls are delegated to.
93069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
94069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    private SessionInputBuffer in = null;
95069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
96069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
97069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Creates a new length limited stream
98069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
99069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param in The session input buffer to wrap
100069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param contentLength The maximum number of bytes that can be read from
101069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * the stream. Subsequent read operations will return -1.
102069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
103069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public ContentLengthInputStream(final SessionInputBuffer in, long contentLength) {
104069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        super();
105069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (in == null) {
106069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Input stream may not be null");
107069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
108069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (contentLength < 0) {
109069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IllegalArgumentException("Content length may not be negative");
110069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
111069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        this.in = in;
112069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        this.contentLength = contentLength;
113069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
114069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
115069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
116069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * <p>Reads until the end of the known length of content.</p>
117069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
118069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * <p>Does not close the underlying socket input, but instead leaves it
119069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * primed to parse the next response.</p>
120069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws IOException If an IO problem occurs.
121069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
122069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public void close() throws IOException {
123069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (!closed) {
124069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            try {
125069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                byte buffer[] = new byte[BUFFER_SIZE];
126069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                while (read(buffer) >= 0) {
127069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                }
128069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            } finally {
129069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                // close after above so that we don't throw an exception trying
130069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                // to read after closed!
131069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                closed = true;
132069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            }
133069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
134069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
135069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
136069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
137069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
138069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Read the next byte from the stream
139069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return The next byte or -1 if the end of stream has been reached.
140069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws IOException If an IO problem occurs
141069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @see java.io.InputStream#read()
142069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
143069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public int read() throws IOException {
144069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (closed) {
145069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IOException("Attempted read from closed stream.");
146069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
147069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
148069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (pos >= contentLength) {
149069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            return -1;
150069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
151069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        pos++;
152069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return this.in.read();
153069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
154069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
155069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
156069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Does standard {@link InputStream#read(byte[], int, int)} behavior, but
157069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * also notifies the watcher when the contents have been consumed.
158069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
159069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param b     The byte array to fill.
160069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param off   Start filling at this position.
161069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param len   The number of bytes to attempt to read.
162069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return The number of bytes read, or -1 if the end of content has been
163069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *  reached.
164069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     *
165069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws java.io.IOException Should an error occur on the wrapped stream.
166069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
167069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public int read (byte[] b, int off, int len) throws java.io.IOException {
168069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (closed) {
169069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            throw new IOException("Attempted read from closed stream.");
170069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
171069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
172069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (pos >= contentLength) {
173069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            return -1;
174069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
175069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
176069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (pos + len > contentLength) {
177069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            len = (int) (contentLength - pos);
178069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
179069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        int count = this.in.read(b, off, len);
180069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        pos += count;
181069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return count;
182069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
183069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
184069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
185069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
186069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Read more bytes from the stream.
187069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param b The byte array to put the new data in.
188069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return The number of bytes read into the buffer.
189069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws IOException If an IO problem occurs
190069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @see java.io.InputStream#read(byte[])
191069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
192069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public int read(byte[] b) throws IOException {
193069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return read(b, 0, b.length);
194069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
195069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project
196069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    /**
197069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * Skips and discards a number of bytes from the input stream.
198069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @param n The number of bytes to skip.
199069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @return The actual number of bytes skipped. <= 0 if no bytes
200069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * are skipped.
201069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @throws IOException If an error occurs while skipping bytes.
202069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     * @see InputStream#skip(long)
203069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project     */
204069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    public long skip(long n) throws IOException {
205069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        if (n <= 0) {
206069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            return 0;
207069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
208069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        byte[] buffer = new byte[BUFFER_SIZE];
209069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        // make sure we don't skip more bytes than are
210069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        // still available
211069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        long remaining = Math.min(n, this.contentLength - this.pos);
212069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        // skip and keep track of the bytes actually skipped
213069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        long count = 0;
214069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        while (remaining > 0) {
215069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            int l = read(buffer, 0, (int)Math.min(BUFFER_SIZE, remaining));
216069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            if (l == -1) {
217069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project                break;
218069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            }
219069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            count += l;
220069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project            remaining -= l;
221069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        }
222069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        this.pos += count;
223069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project        return count;
224069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project    }
225069490a5ca2fd1988d29daf45d892f47ad665115The Android Open Source Project}
226