use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class Medias method getJarResourcesPrefix.
/**
* Get the running JAR resources prefix folder. Load from JAR must be enabled.
*
* @return The resources prefix folder.
* @throws LionEngineException If JAR not available.
*/
public static synchronized String getJarResourcesPrefix() {
if (!loader.isPresent()) {
throw new LionEngineException(JAR_LOADER_ERROR);
}
final Media media = Medias.create(Constant.EMPTY_STRING);
final String path = media.getFile().getPath().replace(File.separator, Constant.SLASH);
final String prefix = loader.get().getPackage().getName().replace(Constant.DOT, Constant.SLASH);
final int jarSeparatorIndex = path.indexOf(prefix);
return path.substring(jarSeparatorIndex).replace(File.separator, Constant.SLASH);
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class UtilSequence method create.
/**
* Create a sequence from its class.
*
* @param nextSequence The next sequence class (must not be <code>null</code>).
* @param context The context reference (must not be <code>null</code>).
* @param arguments The arguments list (must not be <code>null</code>).
* @return The sequence instance.
* @throws LionEngineException If not able to create the sequence for any reason.
*/
public static Sequencable create(Class<? extends Sequencable> nextSequence, Context context, Object... arguments) {
Check.notNull(nextSequence);
Check.notNull(context);
Check.notNull(arguments);
try {
final Class<?>[] params = getParamTypes(context, arguments);
return UtilReflection.create(nextSequence, params, getParams(context, arguments));
} catch (final NoSuchMethodException exception) {
throw new LionEngineException(exception);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class ImageInfo method read.
/**
* Read image header.
*
* @param media The media to read (must not be <code>null</code>).
* @param reader The header reader (must not be <code>null</code>).
* @return The header read.
* @throws LionEngineException If invalid arguments or cannot be read.
*/
private static ImageHeader read(Media media, ImageHeaderReader reader) {
Check.notNull(media);
Check.notNull(reader);
try (InputStream input = media.getInputStream()) {
return reader.readHeader(input);
} catch (final IOException exception) {
throw new LionEngineException(exception, ERROR_READ);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class DocumentFactory method getDocumentFactory.
/**
* Get the document factory.
*
* @return The document factory.
* @throws LionEngineException If unable to create builder.
*/
private static synchronized DocumentBuilder getDocumentFactory() {
if (documentBuilder == null) {
final DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
documentBuilderFactory.setIgnoringElementContentWhitespace(true);
try {
documentBuilderFactory.setFeature(javax.xml.XMLConstants.FEATURE_SECURE_PROCESSING, true);
} catch (final ParserConfigurationException exception) {
Verbose.exception(exception);
}
try {
documentBuilder = documentBuilderFactory.newDocumentBuilder();
documentBuilder.setErrorHandler(null);
} catch (final ParserConfigurationException exception) {
throw new LionEngineException(exception);
}
}
return documentBuilder;
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class Xml method write.
/**
* Write a data to the root.
*
* @param attribute The attribute name (must not be <code>null</code>).
* @param content The content value (must not be <code>null</code>).
* @throws LionEngineException If error when setting the attribute.
*/
private void write(String attribute, String content) {
Check.notNull(attribute);
Check.notNull(content);
try {
root.setAttribute(attribute, content);
} catch (final DOMException exception) {
throw new LionEngineException(exception, ERROR_WRITE_ATTRIBUTE + attribute + ERROR_WRITE_CONTENT + content);
}
}
Aggregations