use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class UtilReflection method getMethod.
/**
* Get method and call its return value with parameters.
*
* @param <T> The object type.
* @param object The object caller (must not be <code>null</code>).
* @param name The method name (must not be <code>null</code>).
* @param params The method parameters (must not be <code>null</code>).
* @return The value returned.
* @throws LionEngineException If invalid parameters.
*/
public static <T> T getMethod(Object object, String name, Object... params) {
Check.notNull(object);
Check.notNull(name);
Check.notNull(params);
try {
final Class<?> clazz = getClass(object);
final Method method = clazz.getDeclaredMethod(name, getParamTypes(params));
setAccessible(method, true);
@SuppressWarnings("unchecked") final T value = (T) method.invoke(object, params);
return value;
} catch (final NoSuchMethodException | InvocationTargetException | IllegalAccessException exception) {
throw new LionEngineException(exception, ERROR_METHOD + name);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class UtilStream method getCopy.
/**
* Get of full copy of the input stream stored in a temporary file.
*
* @param name The file name reference, to have a similar temporary file name (must not be <code>null</code>).
* @param input The input stream reference (must not be <code>null</code>).
* @return The temporary file created with copied content from stream.
* @throws LionEngineException If invalid arguments or invalid stream.
*/
public static File getCopy(String name, InputStream input) {
Check.notNull(name);
Check.notNull(input);
final String prefix;
final String suffix;
final int minimumPrefix = 3;
final int i = name.lastIndexOf(Constant.DOT);
if (i > minimumPrefix) {
prefix = name.substring(0, i);
suffix = name.substring(i);
} else {
if (name.length() > minimumPrefix) {
prefix = name;
} else {
prefix = PREFIX_TEMP;
}
suffix = null;
}
try {
final File temp = File.createTempFile(prefix, suffix);
try (OutputStream output = new BufferedOutputStream(new FileOutputStream(temp))) {
copy(input, output);
}
return temp;
} catch (final IOException exception) {
throw new LionEngineException(exception, ERROR_TEMP_FILE + name);
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class UtilZip method getEntriesByExtension.
/**
* Get all entries existing in the path considering the extension.
*
* @param jar The JAR to check (must not be <code>null</code>).
* @param path The path to check (must not be <code>null</code>).
* @param extension The extension without dot; eg: xml (must not be <code>null</code>).
* @return The entries list.
* @throws LionEngineException If invalid arguments or unable to open ZIP.
*/
public static Collection<ZipEntry> getEntriesByExtension(File jar, String path, String extension) {
Check.notNull(jar);
Check.notNull(path);
Check.notNull(extension);
try (ZipFile zip = new ZipFile(jar)) {
return checkEntries(zip, path, extension);
} catch (final IOException exception) {
throw new LionEngineException(exception, ERROR_OPEN_ZIP + jar.getAbsolutePath());
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class ExtractorModelTest method testEnumFail.
/**
* Test with enum fail.
*
* @throws NoSuchFieldException If error.
* @throws IllegalArgumentException If error.
* @throws IllegalAccessException If error.
*/
@Test
public void testEnumFail() throws NoSuchFieldException, IllegalArgumentException, IllegalAccessException {
final ExtractorModel extractor = new ExtractorModel(services);
final Field field = extractor.getClass().getDeclaredField("state");
UtilReflection.setAccessible(field, true);
field.set(extractor, ExtractorState.values()[5]);
try {
extractor.update(1.0);
Assert.fail();
} catch (final LionEngineException exception) {
Assert.assertEquals("Unknown enum: FAIL", exception.getMessage());
}
}
use of com.b3dgs.lionengine.LionEngineException in project lionengine by b3dgs.
the class ClientImpl method connect.
/*
* Client
*/
@Override
public void connect(String ip, int port) {
Check.notNull(ip);
Check.superiorOrEqual(port, 0);
Check.inferiorOrEqual(port, Constant.MAX_PORT);
try {
socket = new Socket(InetAddress.getByName(ip), port);
out = new ObjectOutputStream(socket.getOutputStream());
in = new ObjectInputStream(socket.getInputStream());
connected = true;
clientId = -1;
pingRequestTimer.start();
bandwidthTimer.start();
} catch (final IOException exception) {
throw new LionEngineException(exception, "Cannot connect to the server !");
}
}
Aggregations