public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof File ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a File object" ); } // Log information logger.debug( "Serializing a File Resource Key..." ); if ( key.getParent() != null ) { throw new ResourceException ( "Unable to serialize a File-ResourceKey with a parent. This type is not expected to have a parent." ); } // Create a string version of the identifier try { final File file = (File) key.getIdentifier(); final String strIdentifier = file.getCanonicalPath(); final String result = ResourceKeyUtils.createStringResourceKey ( key.getSchema().toString(), strIdentifier, key.getFactoryParameters() ); logger.debug( "Serialized File Resource Key: [" + result + "]" ); return result; } catch ( IOException ioe ) { throw new IllegalArgumentException( "Could not determine cononical path to file specified in ResourceKey: " + ioe.getMessage() ); } }
/** * Creates a String version of the resource key that can be used to generate a new ResourceKey object via * deserialization * * @param bundleKey * @param key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof byte[] ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a byte[] object" ); } final byte[] data = (byte[]) key.getIdentifier(); final char[] cdata = new char[ data.length ]; for ( int i = 0; i < data.length; i++ ) { cdata[ i ] = (char) ( data[ i ] & 0xFF ); } return ResourceKeyUtils.createStringResourceKey ( String.valueOf( key.getSchema() ), new String( cdata ), key.getFactoryParameters() ); }
/** * Serializes the resource key to a String representation which can be recreated using the * <code>deserialize(ResourceKey)<code> method. * * @param bundleKey * @param key * @return a <code>String<code> which is a serialized version of the <code>ResourceKey</code> * @throws ResourceException indicates an error serializing the resource key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof String ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a byte[] object" ); } final String data = (String) key.getIdentifier(); return ResourceKeyUtils.createStringResourceKey ( String.valueOf( key.getSchema() ), data, key.getFactoryParameters() ); }
final String result = ResourceKeyUtils.createStringResourceKey ( key.getSchema().toString(), url.toExternalForm(), key.getFactoryParameters() ); logger.debug( "Serialized Classloader Resource Key: [" + result + "]" );
/** * Creates a String version of the resource key that can be used to generate a new ResourceKey object via * deserialization * * @param bundleKey * @param key */ public String serialize( final ResourceKey bundleKey, final ResourceKey key ) throws ResourceException { // Validate the parameter if ( key == null ) { throw new NullPointerException( "The ResourceKey can not be null" ); } if ( isSupportedKey( key ) == false ) { throw new IllegalArgumentException( "Key format is not recognized." ); } if ( !( key.getIdentifier() instanceof String ) ) { throw new IllegalArgumentException( "ResourceKey is invalid - identifier is not a String object" ); } // Log information logger.debug( "Serializing a Classloader Resource Key..." ); if ( key.getParent() != null ) { throw new ResourceException ( "Cannot serialize this key, it contains a parent, but should not contain one at all." ); } // Serialize the key final String result = ResourceKeyUtils.createStringResourceKey( key.getSchema().toString(), (String) key.getIdentifier(), key.getFactoryParameters() ); logger.debug( "Serialized Classloader Resource Key: [" + result + "]" ); return result; }