OpenShot Library | OpenShotAudio  0.2.2
juce_FileInputStream.h
1 
2 /** @weakgroup juce_core-files
3  * @{
4  */
5 /*
6  ==============================================================================
7 
8  This file is part of the JUCE library.
9  Copyright (c) 2017 - ROLI Ltd.
10 
11  JUCE is an open source library subject to commercial or open-source
12  licensing.
13 
14  The code included in this file is provided under the terms of the ISC license
15  http://www.isc.org/downloads/software-support-policy/isc-license. Permission
16  To use, copy, modify, and/or distribute this software for any purpose with or
17  without fee is hereby granted provided that the above copyright notice and
18  this permission notice appear in all copies.
19 
20  JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
21  EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
22  DISCLAIMED.
23 
24  ==============================================================================
25 */
26 
27 namespace juce
28 {
29 
30 //==============================================================================
31 /**
32  An input stream that reads from a local file.
33 
34  @see InputStream, FileOutputStream, File::createInputStream
35 
36  @tags{Core}
37 */
39 {
40 public:
41  //==============================================================================
42  /** Creates a FileInputStream to read from the given file.
43 
44  After creating a FileInputStream, you should use openedOk() or failedToOpen()
45  to make sure that it's OK before trying to read from it! If it failed, you
46  can call getStatus() to get more error information.
47  */
48  explicit FileInputStream (const File& fileToRead);
49 
50  /** Destructor. */
51  ~FileInputStream() override;
52 
53  //==============================================================================
54  /** Returns the file that this stream is reading from. */
55  const File& getFile() const noexcept { return file; }
56 
57  /** Returns the status of the file stream.
58  The result will be ok if the file opened successfully. If an error occurs while
59  opening or reading from the file, this will contain an error message.
60  */
61  const Result& getStatus() const noexcept { return status; }
62 
63  /** Returns true if the stream couldn't be opened for some reason.
64  @see getResult()
65  */
66  bool failedToOpen() const noexcept { return status.failed(); }
67 
68  /** Returns true if the stream opened without problems.
69  @see getResult()
70  */
71  bool openedOk() const noexcept { return status.wasOk(); }
72 
73 
74  //==============================================================================
75  int64 getTotalLength() override;
76  int read (void*, int) override;
77  bool isExhausted() override;
78  int64 getPosition() override;
79  bool setPosition (int64) override;
80 
81 private:
82  //==============================================================================
83  const File file;
84  void* fileHandle = nullptr;
85  int64 currentPosition = 0;
86  Result status { Result::ok() };
87 
88  void openHandle();
89  size_t readInternal (void*, size_t);
90 
91  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (FileInputStream)
92 };
93 
94 } // namespace juce
95 
96 /** @}*/
An input stream that reads from a local file.
bool failedToOpen() const noexcept
Returns true if the stream couldn't be opened for some reason.
bool openedOk() const noexcept
Returns true if the stream opened without problems.
~FileInputStream() override
Destructor.
const Result & getStatus() const noexcept
Returns the status of the file stream.
const File & getFile() const noexcept
Returns the file that this stream is reading from.
Represents a local file or directory.
Definition: juce_File.h:45
The base class for streams that read data.
Represents the 'success' or 'failure' of an operation, and holds an associated error message to descr...
Definition: juce_Result.h:61
static Result ok() noexcept
Creates and returns a 'successful' result.
Definition: juce_Result.h:65
#define JUCE_API
This macro is added to all JUCE public class declarations.