View Javadoc

1   ////////////////////////////////////////////////////////////////////////////////
2   // MillScript-Excel: an Open Spice interpreter and batch website creation tool
3   // Copyright (C) 2006 Open World Ltd, Kevin Rogers
4   //
5   // This file is part of MillScript-Excel.
6   //
7   // MillScript-Excel is free software; you can redistribute it and/or modify it under
8   // the terms of the GNU General Public License as published by the Free
9   // Software Foundation; either version 2 of the License, or (at your option)
10  // any later version.
11  //
12  // MillScript-Excel is distributed in the hope that it will be useful, but WITHOUT
13  // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14  // FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
15  // more details.
16  //
17  // You should have received a copy of the GNU General Public License along with
18  // MillScript-Excel; if not, write to the Free Software Foundation, Inc., 59 Temple
19  // Place, Suite 330, Boston, MA  02111-1307  USA
20  ////////////////////////////////////////////////////////////////////////////////
21  package org.millscript.office.compound.vfs;
22  
23  import org.millscript.commons.alert.alerts.Unimplemented;
24  import org.millscript.commons.vfs.AbstractVFile;
25  import org.millscript.commons.vfs.alerts.VEntryNotFoundAlert;
26  import org.millscript.office.compound.DirectoryEntry;
27  import org.millscript.office.compound.DirectoryEntryType;
28  
29  import java.io.ByteArrayInputStream;
30  import java.io.InputStream;
31  import java.io.OutputStream;
32  
33  /**
34   * 
35   */
36  public class CompoundDocumentFile extends AbstractVFile< CompoundDocumentVolume > {
37  
38      private final DirectoryEntry entry;
39  
40      public CompoundDocumentFile( final CompoundDocumentFolder parent, final String name ) {
41          super( parent.getVolume(), parent, name );
42          this.entry = null;
43      }
44  
45      public CompoundDocumentFile( final CompoundDocumentFolder parent, final int did ) {
46          super(
47              parent.getVolume(),
48              parent,
49              parent.getVolume().getDirectoryEntry( did ).getName()
50          );
51          this.entry = parent.getVolume().getDirectoryEntry( did );
52      }
53  
54      /**
55       * @see org.millscript.commons.vfs.VFile#getAppendOutputStream()
56       */
57      public OutputStream getAppendOutputStream() {
58          // TODO Auto-generated method stub
59          throw new Unimplemented(
60              "A getAppendOutputStream operation was required"
61          ).culprit( "class", this.getClass() );
62      }
63  
64      /**
65       * @see org.millscript.commons.vfs.VFile#getInputStream()
66       */
67      public InputStream getInputStream() {
68          // TODO Example code only - must add support for short streams
69          // Check if we have an entry and it is of the right type
70          if ( this.entry == null || this.entry.getType() == DirectoryEntryType.EMPTY ) {
71              throw VEntryNotFoundAlert.entryDoesNotExist( this ).mishap();
72          } else if ( this.entry.getType() != DirectoryEntryType.USER_STREAM ) {
73              throw VEntryNotFoundAlert.entryIsNotAFile( this ).culprit(
74                  "entry type",
75                  this.entry.getType()
76              ).mishap();
77          } else {
78              return new ByteArrayInputStream( this.getVolume().readStream( this.entry ) );
79          }
80      }
81  
82      /**
83       * @see org.millscript.commons.vfs.VFile#getOutputStream()
84       */
85      public OutputStream getOutputStream() {
86          // TODO Auto-generated method stub
87          throw new Unimplemented(
88              "A getOutputStream operation was required"
89          ).culprit( "class", this.getClass() );
90      }
91  
92      /**
93       * @see org.millscript.commons.vfs.VEntry#exists()
94       */
95      public boolean exists() {
96          // This is sufficient, at least for the moment.
97          return this.entry != null;
98      }
99  
100 }