Make Exported just be SquirrelJMEVendorApi.
[SquirrelJME.git] / modules / common-vm / src / main / java / cc / squirreljme / vm / SummerCoatJarLibrary.java
blob24df55dc8aa4b4271d2103c8399542bcb8a5c34a
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 java.io.IOException;
13 import java.io.InputStream;
14 import java.nio.file.Files;
15 import java.nio.file.Path;
16 import java.nio.file.StandardOpenOption;
18 /**
19 * Jar Library for SummerCoat.
21 * @since 2020/11/23
23 public class SummerCoatJarLibrary
24 implements VMClassLibrary
26 /** Special name for SummerCoat ROM chunk. */
27 public static final String ROM_CHUNK_RESOURCE =
28 "$$SQUIRRELJME$SUMMERCOAT$$";
30 /** The path to the ROM. */
31 protected final Path path;
33 /**
34 * Initializes the ROM library.
36 * @param __path The ROM path.
37 * @throws NullPointerException On null arguments.
38 * @since 2020/11/23
40 public SummerCoatJarLibrary(Path __path)
41 throws NullPointerException
43 if (__path == null)
44 throw new NullPointerException("NARG");
46 this.path = __path;
49 /**
50 * {@inheritDoc}
51 * @since 2020/11/23
53 @Override
54 public String[] listResources()
56 // There is only ever a single resource
57 return new String[]{SummerCoatJarLibrary.ROM_CHUNK_RESOURCE};
60 /**
61 * {@inheritDoc}
62 * @since 2020/11/23
64 @Override
65 public String name()
67 return this.path.getFileName().toString();
70 /**
71 * {@inheritDoc}
72 * @since 2021/06/13
74 @Override
75 public Path path()
77 return this.path;
80 /**
81 * {@inheritDoc}
82 * @since 2020/11/23
84 @Override
85 public InputStream resourceAsStream(String __rc)
86 throws IOException, NullPointerException
88 if (__rc == null)
89 throw new NullPointerException("NARG");
91 // Not our ROM chunk?
92 if (!SummerCoatJarLibrary.ROM_CHUNK_RESOURCE.equals(__rc))
93 return null;
95 return Files.newInputStream(this.path, StandardOpenOption.READ);
98 /**
99 * {@inheritDoc}
100 * @since 2020/11/27
102 @Override
103 public String toString()
105 return this.name();
109 * Checks if this is a SQC or not.
111 * @param __s The file name.
112 * @return If this is a SQC ROM.
113 * @throws NullPointerException On null arguments.
114 * @since 2020/11/27
116 public static boolean isSqc(Path __s)
117 throws NullPointerException
119 if (__s == null)
120 throw new NullPointerException("NARG");
122 return SummerCoatJarLibrary.isSqc(__s.toString());
126 * Checks if this is a SQC or not.
128 * @param __s The file name.
129 * @return If this is a SQC ROM.
130 * @throws NullPointerException On null arguments.
131 * @since 2020/11/27
133 public static boolean isSqc(String __s)
134 throws NullPointerException
136 if (__s == null)
137 throw new NullPointerException("NARG");
139 return __s.endsWith(".sqc") || __s.endsWith(".SQC");