 |
Gridarta Editor
|
Go to the documentation of this file.
20 package net.sf.gridarta.model.face;
22 import java.io.BufferedReader;
23 import java.io.ByteArrayOutputStream;
25 import java.io.FileInputStream;
26 import java.io.FileNotFoundException;
27 import java.io.IOException;
28 import java.io.InputStream;
29 import java.io.InputStreamReader;
30 import java.io.Reader;
32 import java.util.regex.Matcher;
33 import java.util.regex.Pattern;
40 import net.
sf.japi.swing.action.ActionBuilder;
41 import net.
sf.japi.swing.action.ActionBuilderFactory;
42 import org.apache.log4j.Category;
43 import org.apache.log4j.Logger;
44 import org.jetbrains.annotations.NotNull;
72 private static final ActionBuilder
ACTION_BUILDER = ActionBuilderFactory.getInstance().getActionBuilder(
"net.sf.gridarta");
93 final File tmpFaceFile;
96 }
catch (
final IOException ex) {
109 BufferedReader treeIn =
null;
112 final InputStream inputStream2 = url.openStream();
115 treeIn =
new BufferedReader(reader);
116 }
catch (
final FileNotFoundException ignored) {
119 final byte[] tag =
"IMAGE ".getBytes();
124 final StringBuilder faceB =
new StringBuilder();
125 while (offset < data.length) {
130 throw new IOException(
"expecting 'IMAGE' at position " + offset);
134 while (data[offset++] != 0x20) {
141 final char c = (char) data[offset++];
145 if (c < '0' || c >
'9') {
146 throw new IOException(
"syntax error at position " + offset +
": not a digit");
154 final char c = (char) data[offset++];
164 final String faceName = faceB.toString().intern();
166 if (offset +
size > data.length) {
167 throw new IOException(
"truncated at position " + offset);
170 if (treeIn !=
null) {
171 final String originalFilename = treeIn.readLine();
172 if (originalFilename ==
null) {
175 final Matcher matcher = pattern.matcher(originalFilename);
176 if (matcher.matches()) {
189 collectedFaceProvider.
addInfo(faceName, offset,
size);
194 if (treeIn !=
null) {
198 }
catch (
final IOException ex) {
202 if (
LOG.isInfoEnabled()) {
203 LOG.info(
"Loaded " + faces +
" faces from '" + tmpFaceFile +
"'.");
205 return collectedFaceProvider;
214 private static byte @NotNull []
getFileContents(@NotNull
final File file)
throws IOException {
215 final ByteArrayOutputStream bufOut =
new ByteArrayOutputStream((
int) file.length());
216 try (InputStream inputStream =
new FileInputStream(file)) {
219 final int len = inputStream.read(buf);
223 bufOut.write(buf, 0, len);
226 return bufOut.toByteArray();
static URL getResource(@NotNull final File dir, @NotNull final String fileName)
Get the URL of a resource.
This interface represents a lazy loader that provides images on demand.
void addWarning(@NotNull final ErrorViewCategory category)
Adds a warning message.
static File getFile(@NotNull final File dir, @NotNull final String fileName)
Returns a File instance for a resource that is a regular file on the file system.
static final ActionBuilder ACTION_BUILDER
Action Builder.
Base package of all Gridarta classes.
FaceObject getDuplicate()
Returns the duplicate that caused this exception.
void addFaceObject(@NotNull final String faceName, @NotNull final String originalFilename, final int offset, final int size)
Adds a new face object.
Abstract base implementation of FaceObjects.
static boolean contains(final byte @NotNull[] src, final int offset, final byte @NotNull[] search)
Helper method that checks whether a region in a byte array at a given offset contains the same as ano...
static final int CHUNK_SIZE
The chunk size in bytes when reading file contents.
Interface for classes displaying error messages.
static byte[] getFileContents(@NotNull final File file)
Returns the contents of a File as a.
void addInfo(@NotNull final String faceName, final int pos, final int size)
Report position and size of a face for loading it later.
Exception thrown to indicate that a face object is not acceptable.
FaceProvider loadFacesCollection(@NotNull final ErrorView errorView, @NotNull final File collectedDirectory)
Loads all faces from a png collection file.
Implementation of FaceProvider which reads images from the collected PNG archive.
Utility class for array related functions.
Convenience class for adding messages to a ErrorView instance using a fixed category name.
boolean isIncludeFaceNumbers()
Returns whether the images file contains face numbers.
Defines possible error categories for ErrorView instances.
A FaceProvider that does not return any faces.
static String getString(@NotNull final ActionBuilder actionBuilder, @NotNull final String key, @NotNull final String defaultValue)
Returns the value of a key.
static final Category LOG
The Logger for printing log messages.
final boolean includeFaceNumbers
Whether the face file contains face numbers.
DefaultFaceObjects(final boolean includeFaceNumbers)
Creates a new instance.
Abstract base class for FaceObjects implementations.
Utility-class for Gridarta's I/O.
String getFaceName()
Get the faceName, which is the name of the face as usable by the "face" attribute.
FaceObject getFaceObject()
Returns the illegal face object.
Utility class for ActionBuilder related functions.
Exception that's thrown in case a face name was not unique.
static final String MAP_ENCODING
Encoding to use for maps and other data.
static final long serialVersionUID
The serial version UID.