Marking of more classes, might get rid of in the future and optimize; Implement shrin...
[SquirrelJME.git] / modules / common-vm / src / main / java / cc / squirreljme / vm / SummerCoatJarLibrary.java
blob207ec2b8c10780e01079a87c9901177dcf8658f6
1 // -*- Mode: Java; indent-tabs-mode: t; tab-width: 4 -*-
2 // ---------------------------------------------------------------------------
3 // SquirrelJME
4 // Copyright (C) Stephanie Gawroriski <xer@multiphasicapps.net>
5 // ---------------------------------------------------------------------------
6 // SquirrelJME is under the GNU General Public License v3+, or later.
7 // See license.mkd for licensing and copyright information.
8 // ---------------------------------------------------------------------------
10 package cc.squirreljme.vm;
12 import cc.squirreljme.runtime.cldc.annotation.Exported;
13 import java.io.IOException;
14 import java.io.InputStream;
15 import java.nio.file.Files;
16 import java.nio.file.Path;
17 import java.nio.file.StandardOpenOption;
19 /**
20 * Jar Library for SummerCoat.
22 * @since 2020/11/23
24 @Exported
25 public class SummerCoatJarLibrary
26 implements VMClassLibrary
28 /** Special name for SummerCoat ROM chunk. */
29 public static final String ROM_CHUNK_RESOURCE =
30 "$$SQUIRRELJME$SUMMERCOAT$$";
32 /** The path to the ROM. */
33 protected final Path path;
35 /**
36 * Initializes the ROM library.
38 * @param __path The ROM path.
39 * @throws NullPointerException On null arguments.
40 * @since 2020/11/23
42 @Exported
43 public SummerCoatJarLibrary(Path __path)
44 throws NullPointerException
46 if (__path == null)
47 throw new NullPointerException("NARG");
49 this.path = __path;
52 /**
53 * {@inheritDoc}
54 * @since 2020/11/23
56 @Override
57 public String[] listResources()
59 // There is only ever a single resource
60 return new String[]{SummerCoatJarLibrary.ROM_CHUNK_RESOURCE};
63 /**
64 * {@inheritDoc}
65 * @since 2020/11/23
67 @Override
68 public String name()
70 return this.path.getFileName().toString();
73 /**
74 * {@inheritDoc}
75 * @since 2021/06/13
77 @Override
78 public Path path()
80 return this.path;
83 /**
84 * {@inheritDoc}
85 * @since 2020/11/23
87 @Override
88 public InputStream resourceAsStream(String __rc)
89 throws IOException, NullPointerException
91 if (__rc == null)
92 throw new NullPointerException("NARG");
94 // Not our ROM chunk?
95 if (!SummerCoatJarLibrary.ROM_CHUNK_RESOURCE.equals(__rc))
96 return null;
98 return Files.newInputStream(this.path, StandardOpenOption.READ);
102 * {@inheritDoc}
103 * @since 2020/11/27
105 @Override
106 public String toString()
108 return this.name();
112 * Checks if this is a SQC or not.
114 * @param __s The file name.
115 * @return If this is a SQC ROM.
116 * @throws NullPointerException On null arguments.
117 * @since 2020/11/27
119 @Exported
120 public static boolean isSqc(Path __s)
121 throws NullPointerException
123 if (__s == null)
124 throw new NullPointerException("NARG");
126 return SummerCoatJarLibrary.isSqc(__s.toString());
130 * Checks if this is a SQC or not.
132 * @param __s The file name.
133 * @return If this is a SQC ROM.
134 * @throws NullPointerException On null arguments.
135 * @since 2020/11/27
137 @Exported
138 public static boolean isSqc(String __s)
139 throws NullPointerException
141 if (__s == null)
142 throw new NullPointerException("NARG");
144 return __s.endsWith(".sqc") || __s.endsWith(".SQC");