aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
diff options
context:
space:
mode:
authorNick Burch <nick@apache.org>2010-12-18 10:18:43 +0000
committerNick Burch <nick@apache.org>2010-12-18 10:18:43 +0000
commitc0e28795c1b2400f90dd6a6dd3687674c694aa4b (patch)
tree2ff70d4459c5a5457666670d1456209487871c2e /src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
parent0b4b029e2a0a4631d66972ea87e855a4515011d8 (diff)
downloadpoi-c0e28795c1b2400f90dd6a6dd3687674c694aa4b.tar.gz
poi-c0e28795c1b2400f90dd6a6dd3687674c694aa4b.zip
Start on lower memory POIFS implementation - data source to provide common access to array of bytes and files
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1050607 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java')
-rw-r--r--src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
new file mode 100644
index 0000000000..7f5e8e6354
--- /dev/null
+++ b/src/java/org/apache/poi/poifs/nio/FileBackedDataSource.java
@@ -0,0 +1,48 @@
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+==================================================================== */
+
+package org.apache.poi.poifs.nio;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+import java.nio.channels.FileChannel;
+
+/**
+ * A POIFS {@link DataSource} backed by a File
+ */
+public class FileBackedDataSource extends DataSource {
+ private FileChannel file;
+ public FileBackedDataSource(FileChannel file) {
+ this.file = file;
+ }
+
+ public void read(ByteBuffer dst, long position) throws IOException {
+ file.read(dst, position);
+ }
+
+ public void write(ByteBuffer src, long position) throws IOException {
+ file.write(src, position);
+ }
+
+ public long size() throws IOException {
+ return file.size();
+ }
+
+ public void close() throws IOException {
+ file.close();
+ }
+}