1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
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
69
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
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
97 return this.entry != null;
98 }
99
100 }