The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.8KB

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