Search in sources :

Example 41 with LionEngineException

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);
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) Media(com.b3dgs.lionengine.Media)

Example 42 with LionEngineException

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);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException)

Example 43 with LionEngineException

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);
    }
}
Also used : LionEngineException(com.b3dgs.lionengine.LionEngineException) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 44 with LionEngineException

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;
}
Also used : DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) LionEngineException(com.b3dgs.lionengine.LionEngineException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 45 with LionEngineException

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);
    }
}
Also used : DOMException(org.w3c.dom.DOMException) LionEngineException(com.b3dgs.lionengine.LionEngineException)

Aggregations

LionEngineException (com.b3dgs.lionengine.LionEngineException)75 IOException (java.io.IOException)13 File (java.io.File)8 OutputStream (java.io.OutputStream)7 ArrayList (java.util.ArrayList)7 XmlReader (com.b3dgs.lionengine.XmlReader)6 Field (java.lang.reflect.Field)6 Test (org.junit.Test)6 Media (com.b3dgs.lionengine.Media)5 Configurer (com.b3dgs.lionengine.game.Configurer)4 UtilFile (com.b3dgs.lionengine.UtilFile)3 Graphic (com.b3dgs.lionengine.graphic.Graphic)3 UtilFile (com.b3dgs.lionengine.util.UtilFile)3 DisplayMode (java.awt.DisplayMode)3 BufferedImage (java.awt.image.BufferedImage)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)3 AfterAll (org.junit.jupiter.api.AfterAll)3 Animation (com.b3dgs.lionengine.Animation)2 AnimationConfig (com.b3dgs.lionengine.game.AnimationConfig)2 Feature (com.b3dgs.lionengine.game.Feature)2