void copyAttachments() throws RepositoryBackendException, RepositoryResourceException {
        Collection<AttachmentResourceImpl> attachments = getAttachmentImpls();
        for (AttachmentResourceImpl at : attachments) {
            AttachmentLinkType linkType = at.getLinkType();
            if ((null == linkType) && (at.getURL() != null)) {
                final File tempFile = new File(getId() + "_" + at.getName());

                try {
                    // Why do we have to specify a return type for the run method and paramatize
                    // PrivilegedExceptionAction to it, this method should have a void return type ideally.
                    AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
                        @Override
                        public Object run() {
                            tempFile.deleteOnExit();
                            return null;
                        }
                    });
                } catch (PrivilegedActionException e) {
                    throw new RepositoryResourceValidationException("Unable to copy attachments", at.getId(), e.getCause());
                }

                try {
                    try {
                        at.downloadToFile(tempFile);
                    } catch (IOException e) {
                        // try once more, if we fail then give up on this asset
                        at.downloadToFile(tempFile);
                    }
                    at.setURL(null);
                    at.setFile(tempFile);
                } catch (IOException e) {
                    // tried twice, give up :(
                    throw new RepositoryBackendIOException("Exception caught while obtaining attachments for resource " + getName(), e, getRepositoryConnection());
                }
            }

            // Reset ID after pulling down (if needed) the attachment
            at.resetId();
        }
    }
void copyAttachments ( ) throws RepositoryBackendException , RepositoryResourceException { Collection < AttachmentResourceImpl > attachments = getAttachmentImpls ( ) ; for ( AttachmentResourceImpl at : attachments ) { AttachmentLinkType linkType = at . getLinkType ( ) ; if ( ( null == linkType ) && ( at . getURL ( ) != null ) ) { final File tempFile = new File ( getId ( ) + "_" + at . getName ( ) ) ; try { AccessController . doPrivileged ( new PrivilegedExceptionAction < Object > ( ) { @ Override public Object run ( ) { tempFile . deleteOnExit ( ) ; return null ; } } ) ; } catch ( PrivilegedActionException e ) { throw new RepositoryResourceValidationException ( "Unable to copy attachments" , at . getId ( ) , e . getCause ( ) ) ; } try { try { at . downloadToFile ( tempFile ) ; } catch ( IOException e ) { at . downloadToFile ( tempFile ) ; } at . setURL ( null ) ; at . setFile ( tempFile ) ; } catch ( IOException e ) { throw new RepositoryBackendIOException ( "Exception caught while obtaining attachments for resource " + getName ( ) , e , getRepositoryConnection ( ) ) ; } } at . resetId ( ) ; } }
@SuppressWarnings("rawtypes")