@Override public Object fromString(String str) { byte[] objBytes = Base64.getDecoder().decode(str); try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(objBytes)); return ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while decoding object", e); throw new CacheException(e); } }
@Override public Object fromString(String encodedObject) { byte[] objBytes = Base64.getDecoder().decode(encodedObject); try { ObjectInputStream ois = new ObjectInputStream(new ByteArrayInputStream(objBytes)); return ois.readObject(); } catch (IOException | ClassNotFoundException e) { log.error("Error while decoding object", e); throw new CacheException(e); } }
log.error(String.valueOf(source[srcOffset]) + ": " + DECODABET[source[srcOffset]]); log.error(String.valueOf(source[srcOffset + 1]) + ": " + DECODABET[source[srcOffset + 1]]); log.error(String.valueOf(source[srcOffset + 2]) + ": " + DECODABET[source[srcOffset + 2]]); log.error(String.valueOf(source[srcOffset + 3]) + ": " + DECODABET[source[srcOffset + 3]]); return -1;
@Override public String toString(Object obj) { if (obj instanceof Serializable) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(Base64.getEncoder().wrap(baos)); oos.writeObject(obj); oos.close(); byte[] base64encoded = baos.toByteArray(); return new String(base64encoded, StandardCharsets.UTF_8); } catch (IOException e) { log.error("Error while encoding object", e); throw new CacheException(e); } } else { throw new IllegalArgumentException("Expected " + obj.getClass() + " to be Serializable!"); } } }
@Override public String toString(Object customType) { if (customType instanceof Serializable) { try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(Base64.getEncoder().wrap(baos)); oos.writeObject(customType); oos.close(); byte[] base64encoded = baos.toByteArray(); try { return new String(base64encoded, "UTF-8"); } catch (UnsupportedEncodingException ex) { // highly unlikely in this part of the Universe return new String(base64encoded); } } catch (IOException e) { log.error("Error while encoding object", e); throw new CacheException(e); } } else { throw new IllegalArgumentException("Expected " + customType.getClass() + " to be Serializable!"); } } }
public static void killServer(AbstractProtocolServer<?> server) { try { if (server != null) server.stop(); } catch (Throwable t) { LOG.error("Error stopping server", t); } }
@AfterClass public static void cleanup() { /** * We need to drop the tables, because of DB2 SQL Error: SQLCODE=-204, SQLSTATE=42704 */ try { if (dbServer1.bucketTable != null && dbServer1.bucketTable.getConnectionUrl().contains("db2")) { dbServer1.bucketTable.dropTable(); dbServer2.bucketTable.dropTable(); } if (dbServer1.stringTable != null && dbServer1.stringTable.getConnectionUrl().contains("db2")) { dbServer1.stringTable.dropTable(); dbServer2.stringTable.dropTable(); } } catch (Exception e) { // catching the exception, because the drop is not part of the tests log.error("Couldn't drop the tables: ", e); } if (rcmFactory != null) { rcmFactory.stopManagers(); } rcmFactory = null; }