/** Close all the {@link Resource} objects in this {@link ResourceList}. */ @Override public void close() { for (final Resource resource : this) { try { resource.close(); } catch (final Exception e) { // Ignore } } } }
/** Close parent resource, which will call {@link #closeInputStream()}. */ @Override public void close() throws IOException { if (parentResource != null) { try { parentResource.close(); } catch (final Exception e) { // Ignore } parentResource = null; } } }
@Override public synchronized void close() { super.close(); // Close inputStream if (byteBuffer != null) { byteBuffer = null; } markAsClosed(); } };
@Override public synchronized void close() { super.close(); // Close inputStream if (byteBuffer != null) { FileUtils.closeDirectByteBuffer(byteBuffer, /* log = */ null); byteBuffer = null; } if (fileChannel != null) { try { fileChannel.close(); } catch (final IOException e) { // Ignore } fileChannel = null; } if (randomAccessFile != null) { try { randomAccessFile.close(); } catch (final IOException e) { // Ignore } randomAccessFile = null; } markAsClosed(); } };
/** * Read each {@link Resource} in this {@link ResourceList} as a {@link ByteBuffer}, pass the {@link ByteBuffer} * to the given {@link InputStreamConsumer}, then release the {@link ByteBuffer} after the * {@link ByteBufferConsumer} returns, by calling {@link Resource#close()}. * * @param byteBufferConsumer * The {@link ByteBufferConsumer}. * @param ignoreIOExceptions * if true, any {@link IOException} thrown while trying to load any of the resources will be silently * ignored. * @throws IllegalArgumentException * if ignoreExceptions is false, and an {@link IOException} is thrown while trying to load any of * the resources. */ public void forEachByteBuffer(final ByteBufferConsumer byteBufferConsumer, final boolean ignoreIOExceptions) { for (final Resource resource : this) { try { final ByteBuffer byteBuffer = resource.read(); byteBufferConsumer.accept(resource, byteBuffer); } catch (final IOException e) { if (!ignoreIOExceptions) { throw new IllegalArgumentException("Could not load resource " + resource, e); } } finally { resource.close(); } } }
/** * Fetch the content of each {@link Resource} in this {@link ResourceList} as a byte array, pass the byte array * to the given {@link ByteArrayConsumer}, then close the underlying InputStream or release the underlying * ByteBuffer by calling {@link Resource#close()}. * * @param byteArrayConsumer * The {@link ByteArrayConsumer}. * @param ignoreIOExceptions * if true, any {@link IOException} thrown while trying to load any of the resources will be silently * ignored. * @throws IllegalArgumentException * if ignoreExceptions is false, and an {@link IOException} is thrown while trying to load any of * the resources. */ public void forEachByteArray(final ByteArrayConsumer byteArrayConsumer, final boolean ignoreIOExceptions) { for (final Resource resource : this) { try { final byte[] resourceContent = resource.load(); byteArrayConsumer.accept(resource, resourceContent); } catch (final IOException e) { if (!ignoreIOExceptions) { throw new IllegalArgumentException("Could not load resource " + resource, e); } } finally { resource.close(); } } }
/** * Fetch an {@link InputStream} for each {@link Resource} in this {@link ResourceList}, pass the * {@link InputStream} to the given {@link InputStreamConsumer}, then close the {@link InputStream} after the * {@link InputStreamConsumer} returns, by calling {@link Resource#close()}. * * @param inputStreamConsumer * The {@link InputStreamConsumer}. * @param ignoreIOExceptions * if true, any {@link IOException} thrown while trying to load any of the resources will be silently * ignored. * @throws IllegalArgumentException * if ignoreExceptions is false, and an {@link IOException} is thrown while trying to open any of * the resources. */ public void forEachInputStream(final InputStreamConsumer inputStreamConsumer, final boolean ignoreIOExceptions) { for (final Resource resource : this) { try { inputStreamConsumer.accept(resource, resource.open()); } catch (final IOException e) { if (!ignoreIOExceptions) { throw new IllegalArgumentException("Could not load resource " + resource, e); } } finally { resource.close(); } } }
classpathResource.close();
/** * Method accept ... * * @param resource * of type Resource * @param byteArray * of type byte[] */ @Override public void accept(Resource resource, byte[] byteArray) { Set<PersistenceUnit> units = getPersistenceUnitsFromFile(byteArray); for (Iterator<PersistenceUnit> iterator = units.iterator(); iterator.hasNext(); ) { PersistenceUnit unit = iterator.next(); for (Property property : unit.getProperties() .getProperty()) { if (property.getName() .equals(PersistenceFileHandler.getIgnorePersistenceUnitProperty()) && "true".equalsIgnoreCase(property.getValue())) { iterator.remove(); } } PersistenceFileHandler.getPersistenceUnits() .add(unit); } resource.close(); }
@Override public synchronized void close() { super.close(); // Close inputStream if (byteBuffer != null) { if (moduleReaderProxy != null) { try { // Release any open ByteBuffer moduleReaderProxy.release(byteBuffer); } catch (final Exception e) { // Ignore } } byteBuffer = null; } if (moduleReaderProxy != null) { // Recycle the (open) ModuleReaderProxy instance. moduleReaderProxyRecycler.recycle(moduleReaderProxy); // Don't call ModuleReaderProxy#close(), leave the ModuleReaderProxy open in the recycler. // Just set the ref to null here. The ModuleReaderProxy will be closed by // ClasspathElementModule#close(). moduleReaderProxy = null; } markAsClosed(); } };
throw new ClassNotFoundException("Could not load classfile for class " + className + " : " + e); } finally { resource.close();
classfileResource.close(); inputStreamOrByteBuffer = null;