/** * 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 ); }
/** * 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; }
byte[] requestAsByteArray = serializer.serialize( remoteCacheRequest ); try remoteCacheResponse = serializer.deSerialize( responseAsByteArray, null );
/** * Creates the file and set the block size in bytes. * <p> * @param file * @param blockSizeBytes * @throws IOException */ public BlockDisk( File file, int blockSizeBytes ) throws IOException { this( file, blockSizeBytes, new StandardSerializer() ); }
/** * @param obj * @return byte[] * @throws IOException * */ @Override public <T> byte[] serialize( T obj ) throws IOException { serializeCount++; return serializer.serialize( obj ); }
/** * @param bytes * @return Object * @throws IOException * @throws ClassNotFoundException * */ @Override public <T> T deSerialize( byte[] bytes, ClassLoader loader ) throws IOException, ClassNotFoundException { deSerializeCount++; return serializer.deSerialize( bytes, loader ); }
/** * Creates the file and set the block size in bytes. * <p> * @param file * @param blockSizeBytes * @throws FileNotFoundException */ public BlockDisk( File file, int blockSizeBytes ) throws FileNotFoundException { this( file, blockSizeBytes, new StandardSerializer() ); }
/** * 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; }
byte[] requestAsByteArray = serializer.serialize( remoteCacheRequest ); try remoteCacheResponse = serializer.deSerialize( responseAsByteArray, null );
/** * @param obj * @return byte[] * @throws IOException * */ @Override public <T> byte[] serialize( T obj ) throws IOException { serializeCount++; return serializer.serialize( obj ); }
/** * @param bytes * @return Object * @throws IOException * @throws ClassNotFoundException * */ @Override public <T> T deSerialize( byte[] bytes, ClassLoader loader ) throws IOException, ClassNotFoundException { deSerializeCount++; return serializer.deSerialize( bytes, loader ); }
/** * 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 ); }
elementSerializer = new StandardSerializer(); if ( log.isInfoEnabled() )
/** * 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; }
/** * 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 ); } }
/** * 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 ); }
elementSerializer = new StandardSerializer(); if ( log.isInfoEnabled() )
/** * 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; }
/** * 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 ); } }
/** * 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 ); }