/** * @param obj * @return byte[] * @throws IOException * */ @Override public <T> byte[] serialize( T obj ) throws IOException { serializeCount++; return serializer.serialize( obj ); }
/** * @param obj * @return byte[] * @throws IOException * */ @Override public <T> byte[] serialize( T obj ) throws IOException { serializeCount++; return serializer.serialize( obj ); }
/** * Write the response to the output stream. * <p> * @param response * @param cacheResponse */ protected void writeResponse( HttpServletResponse response, RemoteCacheResponse<Object> cacheResponse ) { try { response.setContentType( "application/octet-stream" ); byte[] responseAsByteAray = serializer.serialize( cacheResponse ); response.setContentLength( responseAsByteAray.length ); OutputStream outputStream = response.getOutputStream(); if ( log.isDebugEnabled() ) { log.debug( "Opened output stream. Response size: " + responseAsByteAray.length ); } // WRITE outputStream.write( responseAsByteAray ); outputStream.flush(); outputStream.close(); } catch ( IOException e ) { log.error( "Problem writing response. " + cacheResponse, e ); } }
/** * Write the response to the output stream. * <p> * @param response * @param cacheResponse */ protected void writeResponse( HttpServletResponse response, RemoteCacheResponse<Serializable> cacheResponse ) { try { response.setContentType( "application/octet-stream" ); byte[] responseAsByteAray = serializer.serialize( cacheResponse ); response.setContentLength( responseAsByteAray.length ); OutputStream outputStream = response.getOutputStream(); if ( log.isDebugEnabled() ) { log.debug( "Opened output stream. Response size: " + responseAsByteAray.length ); } // WRITE outputStream.write( responseAsByteAray ); outputStream.flush(); outputStream.close(); } catch ( Exception e ) { log.error( "Problem writing response. " + cacheResponse, e ); } }
final byte[] bytes = serializer.serialize( message );
final byte[] bytes = serializer.serialize( message );
/** * Total from the start to the endPostion. * <p> * @param elements * @param startPosition * @param endPosition * @return size * @throws IOException */ public static <K, V> long totalSize( ICacheElement<K, V>[] elements, int startPosition, int endPosition ) throws IOException { StandardSerializer serializer = new StandardSerializer(); long total = 0; for ( int i = startPosition; i < endPosition; i++ ) { int tileSize = serializer.serialize( elements[i] ).length + IndexedDisk.HEADER_SIZE_BYTES; total += tileSize; } return total; }
/** * Total from the start to the endPostion. * <p> * @param testObjects * @param endPosition * @return size * @throws IOException */ public static long totalSize( DiskTestObject[] testObjects, int endPosition ) throws IOException { StandardSerializer serializer = new StandardSerializer(); long total = 0; for ( int i = 0; i < endPosition; i++ ) { int tileSize = serializer.serialize( testObjects[i] ).length + IndexedDisk.HEADER_SIZE_BYTES; total += tileSize; } return total; }
/** * Total from the start to the endPostion. * <p> * @param elements * @param startPosition * @param endPosition * @return size * @throws IOException */ public static <K extends Serializable, V extends Serializable> long totalSize( ICacheElement<K, V>[] elements, int startPosition, int endPosition ) throws IOException { StandardSerializer serializer = new StandardSerializer(); long total = 0; for ( int i = startPosition; i < endPosition; i++ ) { int tileSize = serializer.serialize( elements[i] ).length + IndexedDisk.HEADER_SIZE_BYTES; total += tileSize; } return total; }
/** * Total from the start to the endPostion. * <p> * @param testObjects * @param endPosition * @return size * @throws IOException */ public static long totalSize( DiskTestObject[] testObjects, int endPosition ) throws IOException { StandardSerializer serializer = new StandardSerializer(); long total = 0; for ( int i = 0; i < endPosition; i++ ) { int tileSize = serializer.serialize( testObjects[i] ).length + IndexedDisk.HEADER_SIZE_BYTES; total += tileSize; } return total; }
byte[] requestAsByteArray = serializer.serialize( remoteCacheRequest );
byte[] requestAsByteArray = serializer.serialize( remoteCacheRequest );
/** * Test simple back and forth with a string. *<p> * @throws Exception */ public void testBigStringBackAndForth() throws Exception { // SETUP StandardSerializer serializer = new StandardSerializer(); String string = "This is my big string ABCDEFGH"; StringBuilder sb = new StringBuilder(); sb.append( string ); for ( int i = 0; i < 4; i++ ) { sb.append( " " + i + sb.toString() ); // big string } String before = sb.toString(); // DO WORK String after = (String) serializer.deSerialize( serializer.serialize( before ), null ); // VERIFY assertEquals( "Before and after should be the same.", before, after ); } }
/** * Test simple back and forth with a string. *<p> * @throws Exception */ public void testBigStringBackAndForth() throws Exception { // SETUP StandardSerializer serializer = new StandardSerializer(); String string = "This is my big string ABCDEFGH"; StringBuilder sb = new StringBuilder(); sb.append( string ); for ( int i = 0; i < 4; i++ ) { sb.append( " " + i + sb.toString() ); // big string } String before = sb.toString(); // DO WORK String after = (String) serializer.deSerialize( serializer.serialize( before ), null ); // VERIFY assertEquals( "Before and after should be the same.", before, after ); } }
/** * Test simple back and forth with a string. *<p> * @throws Exception */ public void testSimpleBackAndForth() throws Exception { // SETUP StandardSerializer serializer = new StandardSerializer(); String before = "adsfdsafdsafdsafdsafdsafdsafdsagfdsafdsafdsfdsafdsafsa333 31231"; // DO WORK String after = (String) serializer.deSerialize( serializer.serialize( before ), null ); // VERIFY assertEquals( "Before and after should be the same.", before, after ); }
/** * Test simple back and forth with a string. *<p> * @throws Exception */ public void testSimpleBackAndForth() throws Exception { // SETUP StandardSerializer serializer = new StandardSerializer(); String before = "adsfdsafdsafdsafdsafdsafdsafdsagfdsafdsafdsfdsafdsafsa333 31231"; // DO WORK String after = (String) serializer.deSerialize( serializer.serialize( before ), null ); // VERIFY assertEquals( "Before and after should be the same.", before, after ); }
byte[] data = elementSerializer.serialize( string );
byte[] data = elementSerializer.serialize(string);
/** * Test serialization with a null object. Verify that we don't get an error. *<p> * @throws Exception */ public void testNullInput() throws Exception { // SETUP StandardSerializer serializer = new StandardSerializer(); String before = null; // DO WORK byte[] serialized = serializer.serialize( before ); //System.out.println( "testNullInput " + serialized ); String after = (String) serializer.deSerialize( serialized, null ); //System.out.println( "testNullInput " + after ); // VERIFY assertNull( "Should have nothing.", after ); }
/** * Test serialization with a null object. Verify that we don't get an error. *<p> * @throws Exception */ public void testNullInput() throws Exception { // SETUP StandardSerializer serializer = new StandardSerializer(); String before = null; // DO WORK byte[] serialized = serializer.serialize( before ); //System.out.println( "testNullInput " + serialized ); String after = (String) serializer.deSerialize( serialized, null ); //System.out.println( "testNullInput " + after ); // VERIFY assertNull( "Should have nothing.", after ); }