summaryrefslogtreecommitdiff
path: root/tools/aapt2/io/FileSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aapt2/io/FileSystem.cpp')
-rw-r--r--tools/aapt2/io/FileSystem.cpp75
1 files changed, 75 insertions, 0 deletions
diff --git a/tools/aapt2/io/FileSystem.cpp b/tools/aapt2/io/FileSystem.cpp
new file mode 100644
index 000000000000..76f87aec6556
--- /dev/null
+++ b/tools/aapt2/io/FileSystem.cpp
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2015 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include "Source.h"
+#include "io/FileSystem.h"
+#include "util/Files.h"
+#include "util/Maybe.h"
+#include "util/StringPiece.h"
+#include "util/Util.h"
+
+#include <utils/FileMap.h>
+
+namespace aapt {
+namespace io {
+
+RegularFile::RegularFile(const Source& source) : mSource(source) {
+}
+
+std::unique_ptr<IData> RegularFile::openAsData() {
+ android::FileMap map;
+ if (Maybe<android::FileMap> map = file::mmapPath(mSource.path, nullptr)) {
+ return util::make_unique<MmappedData>(std::move(map.value()));
+ }
+ return {};
+}
+
+const Source& RegularFile::getSource() const {
+ return mSource;
+}
+
+FileCollectionIterator::FileCollectionIterator(FileCollection* collection) :
+ mCurrent(collection->mFiles.begin()), mEnd(collection->mFiles.end()) {
+}
+
+bool FileCollectionIterator::hasNext() {
+ return mCurrent != mEnd;
+}
+
+IFile* FileCollectionIterator::next() {
+ IFile* result = mCurrent->second.get();
+ ++mCurrent;
+ return result;
+}
+
+IFile* FileCollection::insertFile(const StringPiece& path) {
+ return (mFiles[path.toString()] = util::make_unique<RegularFile>(Source(path))).get();
+}
+
+IFile* FileCollection::findFile(const StringPiece& path) {
+ auto iter = mFiles.find(path.toString());
+ if (iter != mFiles.end()) {
+ return iter->second.get();
+ }
+ return nullptr;
+}
+
+std::unique_ptr<IFileCollectionIterator> FileCollection::iterator() {
+ return util::make_unique<FileCollectionIterator>(this);
+}
+
+} // namespace io
+} // namespace aapt