2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_BUFFEREDINPUTSTREAM_JUCEHEADER__
27 #define __JUCE_BUFFEREDINPUTSTREAM_JUCEHEADER__
29 #include "juce_InputStream.h"
30 #include "../../memory/juce_OptionalScopedPointer.h"
31 #include "../../memory/juce_HeapBlock.h"
34 //==============================================================================
35 /** Wraps another input stream, and reads from it using an intermediate buffer
37 If you're using an input stream such as a file input stream, and making lots of
38 small read accesses to it, it's probably sensible to wrap it in one of these,
39 so that the source stream gets accessed in larger chunk sizes, meaning less
40 work for the underlying stream.
42 class JUCE_API BufferedInputStream
: public InputStream
45 //==============================================================================
46 /** Creates a BufferedInputStream from an input source.
48 @param sourceStream the source stream to read from
49 @param bufferSize the size of reservoir to use to buffer the source
50 @param deleteSourceWhenDestroyed whether the sourceStream that is passed in should be
51 deleted by this object when it is itself deleted.
53 BufferedInputStream (InputStream
* sourceStream
,
55 bool deleteSourceWhenDestroyed
);
57 /** Creates a BufferedInputStream from an input source.
59 @param sourceStream the source stream to read from - the source stream must not
60 be deleted until this object has been destroyed.
61 @param bufferSize the size of reservoir to use to buffer the source
63 BufferedInputStream (InputStream
& sourceStream
, int bufferSize
);
67 This may also delete the source stream, if that option was chosen when the
68 buffered stream was created.
70 ~BufferedInputStream();
73 //==============================================================================
74 int64
getTotalLength();
76 bool setPosition (int64 newPosition
);
77 int read (void* destBuffer
, int maxBytesToRead
);
83 //==============================================================================
84 OptionalScopedPointer
<InputStream
> source
;
86 int64 position
, lastReadPos
, bufferStart
, bufferOverlap
;
87 HeapBlock
<char> buffer
;
88 void ensureBuffered();
90 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (BufferedInputStream
);
93 #endif // __JUCE_BUFFEREDINPUTSTREAM_JUCEHEADER__