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.

97 lines
3.5KB

  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_FILEINPUTSTREAM_JUCEHEADER__
  19. #define __JUCE_FILEINPUTSTREAM_JUCEHEADER__
  20. #include "juce_File.h"
  21. #include "../streams/juce_InputStream.h"
  22. //==============================================================================
  23. /**
  24. An input stream that reads from a local file.
  25. @see InputStream, FileOutputStream, File::createInputStream
  26. */
  27. class JUCE_API FileInputStream : public InputStream
  28. {
  29. public:
  30. //==============================================================================
  31. /** Creates a FileInputStream.
  32. @param fileToRead the file to read from - if the file can't be accessed for some
  33. reason, then the stream will just contain no data
  34. */
  35. explicit FileInputStream (const File& fileToRead);
  36. /** Destructor. */
  37. ~FileInputStream();
  38. //==============================================================================
  39. /** Returns the file that this stream is reading from. */
  40. const File& getFile() const noexcept { return file; }
  41. /** Returns the status of the file stream.
  42. The result will be ok if the file opened successfully. If an error occurs while
  43. opening or reading from the file, this will contain an error message.
  44. */
  45. const Result& getStatus() const noexcept { return status; }
  46. /** Returns true if the stream couldn't be opened for some reason.
  47. @see getResult()
  48. */
  49. bool failedToOpen() const noexcept { return status.failed(); }
  50. /** Returns true if the stream opened without problems.
  51. @see getResult()
  52. */
  53. bool openedOk() const noexcept { return status.wasOk(); }
  54. //==============================================================================
  55. int64 getTotalLength();
  56. int read (void* destBuffer, int maxBytesToRead);
  57. bool isExhausted();
  58. int64 getPosition();
  59. bool setPosition (int64 pos);
  60. private:
  61. //==============================================================================
  62. File file;
  63. void* fileHandle;
  64. int64 currentPosition;
  65. Result status;
  66. bool needToSeek;
  67. void openHandle();
  68. void closeHandle();
  69. size_t readInternal (void* buffer, size_t numBytes);
  70. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileInputStream);
  71. };
  72. #endif // __JUCE_FILEINPUTSTREAM_JUCEHEADER__