public static void writeAsZip( final File target, final DocumentBundle bundle ) throws IOException, ContentIOException { if ( target == null ) { throw new NullPointerException(); } if ( bundle == null ) { throw new NullPointerException(); } final FileOutputStream fout = new FileOutputStream( target ); final BufferedOutputStream bout = new BufferedOutputStream( fout ); try { writeAsZip( bout, bundle ); } finally { bout.close(); } }
public static void writeReportToZipFile( final MasterReport report, final File file ) throws IOException, BundleWriterException, ContentIOException { if ( report == null ) { throw new NullPointerException(); } if ( file == null ) { throw new NullPointerException(); } final MemoryDocumentBundle outputBundle = new MemoryDocumentBundle(); final BundleWriter writer = new BundleWriter(); writer.writeReport( outputBundle, report ); BundleUtilities.writeAsZip( file, outputBundle ); }
public static void writeReportToZipStream( final MasterReport report, final OutputStream out ) throws IOException, BundleWriterException, ContentIOException { if ( report == null ) { throw new NullPointerException(); } if ( out == null ) { throw new NullPointerException(); } final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle(); final BundleWriter writer = new BundleWriter(); writer.writeReport( documentBundle, report ); BundleUtilities.writeAsZip( out, documentBundle ); }
/** * A helper method that serializes the element object. * * @param stream * the stream to which the element should be serialized. * @throws IOException * if an IO error occured or a property was not serializable. */ private void writeObject( final ObjectOutputStream stream ) throws IOException { stream.defaultWriteObject(); try { final DocumentBundle bundle = getBundle(); stream.writeObject( bundle.getMetaData().getBundleType() ); final MemoryDocumentBundle mem = new MemoryDocumentBundle(); BundleUtilities.copyStickyInto( mem, bundle ); BundleUtilities.copyInto( mem, bundle, LegacyBundleResourceRegistry.getInstance().getRegisteredFiles(), true ); BundleUtilities.copyMetaData( mem, bundle ); mem.getWriteableDocumentMetaData().setBundleType( "application/vnd.pentaho.serialized-bundle" ); final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); BundleUtilities.writeAsZip( outputStream, mem ); stream.writeObject( outputStream.toByteArray() ); } catch ( ContentIOException e ) { throw new IOException( "Unable to serialize the bundle", e ); } }
public static void writeReportToZipStream( final MasterReport report, final OutputStream out, final DocumentMetaData metaData ) throws IOException, BundleWriterException, ContentIOException { if ( report == null ) { throw new NullPointerException(); } if ( out == null ) { throw new NullPointerException(); } final MemoryDocumentBundle documentBundle = new MemoryDocumentBundle(); final BundleWriter writer = new BundleWriter(); writer.writeReport( documentBundle, report ); // restore the metadata to match the metadata of the original bundle. final WriteableDocumentMetaData targetMetaData = (WriteableDocumentMetaData) documentBundle.getMetaData(); for ( final String namespace : metaData.getMetaDataNamespaces() ) { for ( final String name : metaData.getMetaDataNames( namespace ) ) { targetMetaData.setBundleAttribute( namespace, name, metaData.getBundleAttribute( namespace, name ) ); } } BundleUtilities.writeAsZip( out, documentBundle ); }