public Resource create( final ResourceManager manager, final ResourceData data, final ResourceKey context ) throws ResourceCreationException, ResourceLoadingException { try { final Properties properties = new Properties(); final InputStream stream = data.getResourceAsStream( manager ); try { properties.load( stream ); } finally { stream.close(); } return new SimpleResource( data.getKey(), properties, Properties.class, data.getVersion( manager ) ); } catch ( IOException e ) { throw new ResourceLoadingException( "Failed to load the properties file.", e ); } }
public Resource create( final ResourceManager caller, final ResourceData data, final ResourceKey context ) throws ResourceLoadingException { final long version = data.getVersion( caller ); final Image image = Toolkit.getDefaultToolkit().createImage( data.getResource( caller ) ); return new SimpleResource( data.getKey(), image, Image.class, version ); } }
private String queryMimeType( final ResourceData resourceData ) throws ResourceLoadingException, IOException { final Object contentType = resourceData.getAttribute( ResourceData.CONTENT_TYPE ); if ( contentType instanceof String ) { return (String) contentType; } // now we are getting very primitive .. (Kids, dont do this at home) final byte[] data = new byte[12]; resourceData.getResource( resourceManager, data, 0, data.length ); return queryMimeType( data ); }
/** * Get the byte stream for this input source. * <p/> * <p>The getEncoding method will return the character encoding for this byte stream, or null if unknown.</p> * * @return The byte stream, or null if none was supplied. * @see #getEncoding * @see #setByteStream */ public InputStream getByteStream() { try { return data.getResourceAsStream( caller ); } catch ( ResourceLoadingException e ) { logger.error( "Unable to create byte-stream: " + data.getKey() ); return null; } }
/** * Creates a new InputSource using the given resource-data and resource-manager as source. * * @param data the resource-data object holding the raw-data. * @param caller the resource manager that is loading the current resource. * @throws ResourceLoadingException if an error occurs. * @see #setPublicId * @see #setSystemId * @see #setByteStream * @see #setCharacterStream * @see #setEncoding */ public ResourceDataInputSource( final ResourceData data, final ResourceManager caller ) throws ResourceLoadingException { if ( data == null ) { throw new NullPointerException( "Data must not be null" ); } if ( caller == null ) { throw new NullPointerException( "ResourceManager must not be null" ); } this.data = data; this.version = data.getVersion( caller ); this.caller = caller; final URL url = caller.toURL( data.getKey() ); if ( url != null ) { setSystemId( url.toExternalForm() ); } }
public ResourceKey getKey() { return data.getKey(); }
private boolean isResourceDataCacheable( final ResourceData data ) { try { return data.getVersion( this ) != -1; } catch ( ResourceLoadingException e ) { return false; } }
public InputStream getResourceAsStream( final ResourceManager caller ) throws ResourceLoadingException { // again, this is going to hurt the performance. final ResourceKey parentKey = key.getParent(); final ResourceData data = caller.load( parentKey ); final ZipInputStream zin = new ZipInputStream( data.getResourceAsStream( caller ) ); try { try { ZipEntry zipEntry = zin.getNextEntry(); while ( zipEntry != null ) { if ( zipEntry.getName().equals( key.getIdentifier() ) == false ) { zipEntry = zin.getNextEntry(); continue; } // read from here .. return zin; } } finally { zin.close(); } } catch ( IOException e ) { throw new ResourceLoadingException ( "Reading the zip-file failed.", e ); } throw new ResourceLoadingException ( "The zip-file did not contain the specified entry" ); }
public int canHandleResource( final ResourceManager caller, final ResourceData data ) throws ResourceCreationException, ResourceLoadingException { try { final byte[] resource = data.getResource( caller ); if ( createImage( resource ) != null ) { return RECOGNIZED_CONTENTTYPE; } } catch ( IOException e ) { // ignore me .. } return REJECTED; }
String contentType = (String) resourceData.getAttribute( ResourceData.CONTENT_TYPE ); if ( contentType == null ) { contentType = "application/octet-stream"; final InputStream stream = resourceData.getResourceAsStream( resourceManager ); try { final OutputStream outStream = bundle.createEntry( targetPath, contentType );
rawData.getResource( resourceManager, buffer, 0, 2 ); if ( buffer[ 0 ] != 'P' || buffer[ 1 ] != 'K' ) { return null; final InputStream stream = rawData.getResourceAsStream( resourceManager ); try { final ZipReadRepository zipReadRepository = new ZipReadRepository( stream );
public int readAt( final long position ) throws IOException { if ( rawData == null ) { try { rawData = loader.load( source ); } catch ( ResourceLoadingException e ) { throw new IOException( "Failed to load the raw data." ); } } final int iPos = (int) ( position & 0x7fffffff ); final byte[] buffer = new byte[ 1 ]; final long length = rawData.getLength(); if ( ( length > -1 ) && ( iPos >= length ) ) { return -1; } try { rawData.getResource( loader, buffer, iPos, 1 ); return buffer[ 0 ]; } catch ( IndexOutOfBoundsException e ) { return -1; } catch ( ResourceLoadingException e ) { throw new IOException( "Failed to read stream." ); } }
public synchronized Object getAttribute( final String key ) { if ( attributes == null ) { attributes = new HashMap(); } else { final Object cached = attributes.get( key ); if ( cached != null ) { return cached; } } final Object value = data.getAttribute( key ); if ( value != null ) { attributes.put( key, value ); } return value; }
public long getLength() { if ( rawData != null ) { return rawData.length; } return data.getLength(); }
db.setErrorHandler( new LoggingErrorHandler() ); final ResourceDataInputSource input = new ResourceDataInputSource( data, manager ); return new DomResource( data.getKey(), db.parse( input ), data.getVersion( manager ) ); } catch ( ParserConfigurationException e ) { throw new ResourceCreationException( "Unable to initialize the XML-Parser", e ); } catch ( SAXException e ) { throw new ResourceCreationException( "Unable to parse the document: " + data.getKey(), e ); } catch ( IOException e ) { throw new ResourceLoadingException( "Unable to read the stream from document: " + data.getKey(), e );
public boolean equals( final Object o ) { if ( this == o ) { return true; } if ( o == null || getClass() != o.getClass() ) { return false; } final ZipEntryKey that = (ZipEntryKey) o; if ( !entryName.equals( that.entryName ) ) { return false; } if ( !zipFile.getKey().equals( that.zipFile.getKey() ) ) { return false; } return true; }
public long getVersion( final ResourceManager caller ) throws ResourceLoadingException { return data.getVersion( caller ); }
final InputStream in = resourceData.getResourceAsStream( manager ); final ByteArrayOutputStream out = new ByteArrayOutputStream(); try {
public synchronized byte[] getResource( final ResourceManager caller ) throws ResourceLoadingException { if ( rawData == null ) { rawData = data.getResource( caller ); } return (byte[]) rawData.clone(); }
throws ResourceCreationException, ResourceLoadingException { try { final InputStream asStream = data.getResourceAsStream( caller ); try { if ( getHeaderFingerprintSize() != 0 ) { data.getAttribute( ResourceData.CONTENT_TYPE ); if ( mimeType != null && canHandleResourceByMimeType( mimeType ) ) { return RECOGNIZED_CONTENTTYPE; data.getAttribute( ResourceData.FILENAME ); if ( fileName != null && canHandleResourceByName( fileName ) ) { return RECOGNIZED_FILE;