001: /*
002: * Copyright 2007 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: */
013: package org.pentaho.repository.filebased.solution;
014:
015: import java.io.FileNotFoundException;
016: import java.io.InputStream;
017: import java.io.OutputStream;
018: import java.security.cert.Certificate;
019: import java.util.Map;
020:
021: import org.apache.commons.vfs.FileContent;
022: import org.apache.commons.vfs.FileContentInfo;
023: import org.apache.commons.vfs.FileObject;
024: import org.apache.commons.vfs.FileSystemException;
025: import org.apache.commons.vfs.RandomAccessContent;
026: import org.apache.commons.vfs.util.RandomAccessMode;
027:
028: public class SolutionRepositoryVfsFileContent implements FileContent {
029:
030: private SolutionRepositoryVfsFileObject fileObject;
031:
032: private InputStream inputStream = null;
033:
034: private boolean isOpen = false;
035:
036: public SolutionRepositoryVfsFileContent(
037: SolutionRepositoryVfsFileObject fileObject) {
038: super ();
039: this .fileObject = fileObject;
040: }
041:
042: public FileObject getFile() {
043: return fileObject;
044: }
045:
046: public long getSize() throws FileSystemException {
047: // not needed for our usage
048: return 0;
049: }
050:
051: public long getLastModifiedTime() throws FileSystemException {
052: // not needed for our usage
053: return 0;
054: }
055:
056: public void setLastModifiedTime(long arg0)
057: throws FileSystemException {
058: // not needed for our usage
059:
060: }
061:
062: public Map getAttributes() throws FileSystemException {
063: // not needed for our usage
064: return null;
065: }
066:
067: public String[] getAttributeNames() throws FileSystemException {
068: // not needed for our usage
069: return null;
070: }
071:
072: public Object getAttribute(String arg0) throws FileSystemException {
073: // not needed for our usage
074: return null;
075: }
076:
077: public void setAttribute(String arg0, Object arg1)
078: throws FileSystemException {
079: // not needed for our usage
080:
081: }
082:
083: public Certificate[] getCertificates() throws FileSystemException {
084: // not needed for our usage
085: return null;
086: }
087:
088: public InputStream getInputStream() throws FileSystemException {
089:
090: try {
091: inputStream = fileObject.getRepository()
092: .getResourceInputStream(fileObject.getFileRef(),
093: true);
094: } catch (FileNotFoundException e) {
095: throw new FileSystemException(e.getLocalizedMessage(), e);
096: }
097: isOpen = true;
098: return inputStream;
099: }
100:
101: public OutputStream getOutputStream() throws FileSystemException {
102: // not needed for our usage
103: return null;
104: }
105:
106: public RandomAccessContent getRandomAccessContent(
107: RandomAccessMode arg0) throws FileSystemException {
108: // not needed for our usage
109: return null;
110: }
111:
112: public OutputStream getOutputStream(boolean arg0)
113: throws FileSystemException {
114: // not needed for our usage
115: return null;
116: }
117:
118: public void close() throws FileSystemException {
119:
120: if (!isOpen) {
121: return;
122: }
123: if (inputStream != null) {
124: try {
125: inputStream.close();
126: } catch (Exception e) {
127: // not much we can do here
128: }
129: }
130: isOpen = false;
131: fileObject.close();
132: }
133:
134: public FileContentInfo getContentInfo() throws FileSystemException {
135: // not needed for our usage
136: return null;
137: }
138:
139: public boolean isOpen() {
140: // not needed for our usage
141: return isOpen;
142: }
143:
144: }
|