@Test public void testMatchedShadedSubstitutionWithUnavailableClass() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); try { ObjectOutputStream oout = new ObjectOutputStream(bout) { @Override public void writeUTF(String str) throws IOException { if (str.equals(AvailableClass.class.getName())) { super.writeUTF("org.terracotta.voltron.proxy.shaded." + str); } else { super.writeUTF(str); } } }; oout.writeObject(new AvailableClass("foobar")); } finally { bout.close(); } byte[] encoded = bout.toByteArray(); SerializationCodec regularCodec = new SerializationCodec(); try { regularCodec.decode(AvailableClass.class, encoded); fail("Expected RuntimeException"); } catch (RuntimeException e) { assertThat(e.getMessage(), containsString("java.lang.ClassNotFoundException: org.terracotta.voltron.proxy.shaded.org.terracotta.AvailableClass")); } SerializationCodec deshadingCodec = new SerializationCodec(Pattern.compile("^org\\.terracotta\\.voltron\\.proxy\\.shaded\\.(.*)$")); AvailableClass foobar = deshadingCodec.decode(AvailableClass.class, encoded); assertThat(foobar.string, is("foobar")); }
@Override public <T> T decode(final Class<T> type, final byte[] buffer) { return decode(type, buffer, 0, buffer.length); }
SerializationCodec implements Codec { @Override public <T> T decode(final Class<T> type, final byte[] buffer) { return decode(type, buffer, 0, buffer.length); } }
SerializationCodec implements Codec { @Override public <T> T decode(final Class<T> type, final byte[] buffer) { return decode(type, buffer, 0, buffer.length); } SerializationCodec();  SerializationCodec(Pattern shadingPattern); }
SerializationCodec implements Codec { @Override public <T> T decode(final Class<T> type, final byte[] buffer) { return decode(type, buffer, 0, buffer.length); } SerializationCodec();  SerializationCodec(Pattern shadingPattern); @Override byte[] encode(final Class<?> type, final Object value); @Override T decode(final Class<T> type, final byte[] buffer); @SuppressWarnings("unchecked") @Override T decode(Class<T> type, byte[] buffer, int offset, int len); @Override byte[] encode(Class<?>[] types, Object[] values); @Override Object[] decode(Class<?>[] types, byte[] buffer); @Override Object[] decode(Class<?>[] types, byte[] buffer, int offset, int len); }
SerializationCodec implements Codec { @Override public <T> T decode(final Class<T> type, final byte[] buffer) { return decode(type, buffer, 0, buffer.length); } SerializationCodec();  SerializationCodec(Pattern shadingPattern); @Override byte[] encode(final Class<?> type, final Object value); @Override T decode(final Class<T> type, final byte[] buffer); @SuppressWarnings("unchecked") @Override T decode(Class<T> type, byte[] buffer, int offset, int len); @Override byte[] encode(Class<?>[] types, Object[] values); @Override Object[] decode(Class<?>[] types, byte[] buffer); @Override Object[] decode(Class<?>[] types, byte[] buffer, int offset, int len);  }