1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // Multi-Phasic Applications: SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the Mozilla Public License Version 2.0.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc
.squirreljme
.vm
.springcoat
;
12 import cc
.squirreljme
.jvm
.mle
.NativeArchiveShelf
;
13 import cc
.squirreljme
.jvm
.mle
.brackets
.NativeArchiveBracket
;
14 import cc
.squirreljme
.jvm
.mle
.brackets
.NativeArchiveEntryBracket
;
15 import cc
.squirreljme
.jvm
.mle
.exceptions
.MLECallError
;
16 import cc
.squirreljme
.vm
.springcoat
.brackets
.NativeArchiveEntryObject
;
17 import cc
.squirreljme
.vm
.springcoat
.brackets
.NativeArchiveObject
;
18 import cc
.squirreljme
.vm
.springcoat
.exceptions
.SpringMLECallError
;
19 import java
.io
.IOException
;
22 * SpringCoat layer for {@link NativeArchiveShelf}.
26 public enum MLENativeArchive
27 implements MLEFunction
29 /** {@link NativeArchiveShelf#archiveClose(NativeArchiveBracket)}. */
30 ARCHIVE_CLOSE("archiveClose:" +
31 "(Lcc/squirreljme/jvm/mle/brackets/NativeArchiveBracket;)V")
38 public Object
handle(SpringThreadWorker __thread
, Object
... __args
)
40 Object archive
= __args
[0];
44 NativeArchiveShelf
.archiveClose(
45 MLENativeArchive
.__archiveObject(archive
).wrapped
);
47 catch (MLECallError __e
)
49 throw new SpringMLECallError(__e
);
57 * {@link NativeArchiveShelf#archiveEntry(NativeArchiveBracket,
60 ARCHIVE_ENTRY("archiveEntry:" +
61 "(Lcc/squirreljme/jvm/mle/brackets/NativeArchiveBracket;" +
62 "Ljava/lang/String)" +
63 "Lcc/squirreljme/jvm/mle/brackets/NativeArchiveEntryBracket;")
70 public Object
handle(SpringThreadWorker __thread
, Object
... __args
)
72 Object archive
= __args
[0];
73 String name
= __thread
.asNativeObject(String
.class, __args
[1]);
77 NativeArchiveEntryBracket entry
=
78 NativeArchiveShelf
.archiveEntry(
79 MLENativeArchive
.__archiveObject(archive
).wrapped
,
82 return SpringNullObject
.NULL
;
84 return new NativeArchiveEntryObject(__thread
.machine
,
87 catch (MLECallError __e
)
89 throw new SpringMLECallError(__e
);
94 /** {@link NativeArchiveShelf#archiveOpenZip(byte[], int, int)}. */
95 ARCHIVE_OPEN_ZIP("archiveOpenZip:" +
96 "([BII)Lcc/squirreljme/jvm/mle/brackets/NativeArchiveBracket;")
103 public Object
handle(SpringThreadWorker __thread
, Object
... __args
)
105 SpringArrayObjectByte buf
= (SpringArrayObjectByte
)__args
[0];
106 int off
= (Integer
)__args
[1];
107 int len
= (Integer
)__args
[2];
111 return new NativeArchiveObject(__thread
.machine
,
112 NativeArchiveShelf
.archiveOpenZip(buf
.array(),
115 catch (MLECallError __e
)
117 throw new SpringMLECallError(__e
);
123 * {@link NativeArchiveShelf#entryIsDirectory(NativeArchiveEntryBracket)}.
125 ENTRY_IS_DIRECTORY("entryIsDirectory:" +
126 "(Lcc/squirreljme/jvm/mle/brackets/NativeArchiveEntryBracket;)Z")
133 public Object
handle(SpringThreadWorker __thread
, Object
... __args
)
135 NativeArchiveEntryObject entry
=
136 MLENativeArchive
.__entryObject(__args
[0]);
140 return NativeArchiveShelf
.entryIsDirectory(entry
.wrapped
);
142 catch (MLECallError __e
)
144 throw new SpringMLECallError(__e
);
149 /** {@link NativeArchiveShelf#entryOpen(NativeArchiveEntryBracket)}. */
150 ENTRY_OPEN("entryOpen:" +
151 "(Lcc/squirreljme/jvm/mle/brackets/NativeArchiveEntryBracket;)" +
152 "Ljava/io/InputStream;")
159 public Object
handle(SpringThreadWorker __thread
, Object
... __args
)
161 NativeArchiveEntryObject entry
=
162 MLENativeArchive
.__entryObject(__args
[0]);
166 return __thread
.proxyInputStream(
167 NativeArchiveShelf
.entryOpen(entry
.wrapped
));
169 catch (MLECallError
|IOException __e
)
171 throw new SpringMLECallError(__e
);
177 * {@link NativeArchiveShelf#entryUncompressedSize(
178 * NativeArchiveEntryBracket)}.
180 ENTRY_UNCOMPRESSED_SIZE("entryUncompressedSize:" +
181 "(Lcc/squirreljme/jvm/mle/brackets/NativeArchiveEntryBracket;)J")
188 public Object
handle(SpringThreadWorker __thread
, Object
... __args
)
190 NativeArchiveEntryObject entry
=
191 MLENativeArchive
.__entryObject(__args
[0]);
195 return NativeArchiveShelf
.entryUncompressedSize(entry
.wrapped
);
197 catch (MLECallError __e
)
199 throw new SpringMLECallError(__e
);
207 /** The dispatch key. */
208 protected final String key
;
211 * Initializes the dispatcher info.
213 * @param __key The key.
214 * @throws NullPointerException On null arguments.
217 MLENativeArchive(String __key
)
218 throws NullPointerException
221 throw new NullPointerException("NARG");
237 * Checks if this is a {@link NativeArchiveObject}.
239 * @param __object The object to check.
240 * @return As one if this is one.
241 * @throws SpringMLECallError If this is not one.
244 static NativeArchiveObject
__archiveObject(Object __object
)
245 throws SpringMLECallError
247 if (!(__object
instanceof NativeArchiveObject
))
248 throw new SpringMLECallError("Not a NativeArchiveObject.");
250 return (NativeArchiveObject
)__object
;
254 * Checks if this is a {@link NativeArchiveEntryObject}.
256 * @param __object The object to check.
257 * @return As one if this is one.
258 * @throws SpringMLECallError If this is not one.
261 static NativeArchiveEntryObject
__entryObject(Object __object
)
262 throws SpringMLECallError
264 if (!(__object
instanceof NativeArchiveEntryObject
))
265 throw new SpringMLECallError(
266 "Not a NativeArchiveEntryObject.");
268 return (NativeArchiveEntryObject
)__object
;