use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class UtilReflection method getField.
/**
* Get the field by reflection.
*
* @param <T> The field type.
* @param object The object to use (must not be <code>null</code>).
* @param name The field name (must not be <code>null</code>).
* @return The field found.
* @throws LionEngineException If invalid parameters or field not found.
*/
public static <T> T getField(Object object, String name) {
Check.notNull(object);
Check.notNull(name);
try {
final Class<?> clazz = getClass(object);
final Field field = getDeclaredFieldSuper(clazz, name);
setAccessible(field, true);
@SuppressWarnings("unchecked") final T value = (T) field.get(object);
return value;
} catch (final NoSuchFieldException | IllegalAccessException exception) {
throw new LionEngineException(exception, ERROR_FIELD + name);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class UtilReflection method create.
/**
* Create a class instance with its parameters.
*
* @param <T> The element type used.
* @param type The class type to instantiate (must not be <code>null</code>).
* @param constructor The constructor to use (must not be <code>null</code>).
* @param params The constructor parameters (must not be <code>null</code>).
* @return The class instance.
* @throws LionEngineException If invalid parameters or unable to create the instance.
*/
private static <T> T create(Class<T> type, Constructor<T> constructor, Object... params) {
Check.notNull(type);
Check.notNull(constructor);
Check.notNull(params);
try {
setAccessible(constructor, true);
return constructor.newInstance(params);
} catch (final IllegalArgumentException exception) {
throw new LionEngineException(exception, ERROR_CONSTRUCTOR + type + " " + Arrays.asList(constructor.getParameterTypes()) + " with " + Arrays.asList(params));
} catch (final InstantiationException | IllegalAccessException | InvocationTargetException exception) {
throw new LionEngineException(exception, ERROR_CONSTRUCTOR + type);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class Sc68Format method loadLibrary.
/**
* Load the library.
*
* @return The library binding.
* @throws LionEngineException If error on loading.
*/
private static Sc68Binding loadLibrary() {
try {
Verbose.info("Load library: ", LIBRARY_NAME);
final Sc68Binding binding = Native.loadLibrary(LIBRARY_NAME, Sc68Binding.class);
Verbose.info("Library ", LIBRARY_NAME, " loaded");
return binding;
} catch (final LinkageError exception) {
throw new LionEngineException(exception, ERROR_LOAD_LIBRARY + LIBRARY_NAME);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class FactoryGraphicAwt method saveImage.
@Override
public void saveImage(ImageBuffer image, Media media) {
Check.notNull(media);
final BufferedImage surface = image.getSurface();
try (OutputStream output = media.getOutputStream()) {
ToolsAwt.saveImage(surface, output);
} catch (final IOException exception) {
throw new LionEngineException(exception, ERROR_IMAGE_SAVE);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class ScreenAwtTest method testHeadless.
/**
* Test headless screen.
*
* @param config The config reference.
* @throws Exception If error.
*/
private void testHeadless(Config config) throws Exception {
final Object old = UtilReflection.getField(GraphicsEnvironment.class, "headless");
final Field field = GraphicsEnvironment.class.getDeclaredField("headless");
UtilReflection.setAccessible(field, true);
field.set(GraphicsEnvironment.class, Boolean.TRUE);
try {
Assert.assertNull(Graphics.createScreen(config));
} catch (final LionEngineException exception) {
Assert.assertTrue(exception.getMessage().equals("No available display !"));
} finally {
field.set(GraphicsEnvironment.class, old);
}
}
Aggregations