• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ANDROID_WEBVIEW_BROWSER_INPUT_STREAM_H_
6 #define ANDROID_WEBVIEW_BROWSER_INPUT_STREAM_H_
7 
8 #include "base/basictypes.h"
9 
10 namespace net {
11 class IOBuffer;
12 }
13 
14 namespace android_webview {
15 
16 // Abstract wrapper used to access the InputStream Java class.
17 // This class is safe to pass around between threads (the destructor,
18 // constructor and methods can be called on different threads) but calling
19 // methods concurrently might have undefined results.
20 class InputStream {
21  public:
~InputStream()22   virtual ~InputStream() {}
23 
24   // Sets |bytes_available| to the number of bytes that can be read (or skipped
25   // over) from this input stream without blocking by the next caller of a
26   // method for this input stream.
27   // Returns true if completed successfully or false if an exception was
28   // thrown.
29   virtual bool BytesAvailable(int* bytes_available) const = 0;
30 
31   // Skips over and discards |n| bytes of data from this input stream. Sets
32   // |bytes_skipped| to the number of of bytes skipped.
33   // Returns true if completed successfully or false if an exception was
34   // thrown.
35   virtual bool Skip(int64_t n, int64_t* bytes_skipped) = 0;
36 
37   // Reads at most |length| bytes into |dest|. Sets |bytes_read| to the total
38   // number of bytes read into |dest| or 0 if there is no more data because the
39   // end of the stream was reached.
40   // |dest| must be at least |length| in size.
41   // Returns true if completed successfully or false if an exception was
42   // thrown.
43   virtual bool Read(net::IOBuffer* dest, int length, int* bytes_read) = 0;
44 
45  protected:
InputStream()46   InputStream() {}
47 };
48 
49 } // namespace android_webview
50 
51 #endif //  ANDROID_WEBVIEW_BROWSER_INPUT_STREAM_H_
52