Add remaining files
[juce-lv2.git] / juce / source / src / io / files / juce_FileInputStream.cpp
blobc2a9ca564ca0ef24118d242c9174be751cdab854
1 /*
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 #include "../../core/juce_StandardHeader.h"
28 BEGIN_JUCE_NAMESPACE
30 #include "juce_FileInputStream.h"
33 //==============================================================================
34 int64 juce_fileSetPosition (void* handle, int64 pos);
37 //==============================================================================
38 FileInputStream::FileInputStream (const File& f)
39 : file (f),
40 fileHandle (nullptr),
41 currentPosition (0),
42 totalSize (0),
43 status (Result::ok()),
44 needToSeek (true)
46 openHandle();
49 FileInputStream::~FileInputStream()
51 closeHandle();
54 //==============================================================================
55 int64 FileInputStream::getTotalLength()
57 return totalSize;
60 int FileInputStream::read (void* buffer, int bytesToRead)
62 if (needToSeek)
64 if (juce_fileSetPosition (fileHandle, currentPosition) < 0)
65 return 0;
67 needToSeek = false;
70 const size_t num = readInternal (buffer, bytesToRead);
71 currentPosition += num;
73 return (int) num;
76 bool FileInputStream::isExhausted()
78 return currentPosition >= totalSize;
81 int64 FileInputStream::getPosition()
83 return currentPosition;
86 bool FileInputStream::setPosition (int64 pos)
88 pos = jlimit ((int64) 0, totalSize, pos);
90 needToSeek |= (currentPosition != pos);
91 currentPosition = pos;
93 return true;
96 END_JUCE_NAMESPACE