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();