Inheritance: java.io.FilterOutputStream
Ejemplo n.º 1
1
        public void UnZip(string zipFileLocation, string destinationRootFolder, string zipRootToRemove)
        {
            try
            {
                var zipFile = new ZipFile(zipFileLocation);
                var zipFileEntries = zipFile.entries();
                
                while (zipFileEntries.hasMoreElements())
                {
                    var zipEntry = (ZipEntry)zipFileEntries.nextElement();

                    var name = zipEntry.getName().Replace(zipRootToRemove, "").Replace("/", "\\").TrimStart('/').TrimStart('\\');
                    var p = this.fileSystem.Path.Combine(destinationRootFolder, name);

                    if (zipEntry.isDirectory())
                    {
                        if (!this.fileSystem.Directory.Exists(p))
                        {
                            this.fileSystem.Directory.CreateDirectory(p);
                        };
                    }
                    else
                    {
                        using (var bis = new BufferedInputStream(zipFile.getInputStream(zipEntry)))
                        {
                            var buffer = new byte[2048];
                            var count = buffer.GetLength(0);
                            using (var fos = new FileOutputStream(p))
                            {
                                using (var bos = new BufferedOutputStream(fos, count))
                                {
                                    int size;
                                    while ((size = bis.read(buffer, 0, count)) != -1)
                                    {
                                        bos.write(buffer, 0, size);
                                    }

                                    bos.flush();
                                    bos.close();
                                }
                            }

                            bis.close();
                        }
                    }
                }

                zipFile.close();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            catch (Exception e)
            {
                var t = e.ToString();
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Start this from directory \samples\samples\fop\
        /// with \samples\lib populated with jni4net.j.jar and jni4net.n.dll
        /// and with \samples\samples\fop\lib populated with FOP jar files.
        /// </summary>
        private static void Main()
        {
            FixStartupDirectory();

            // automaticaly setup Java classpath to find jni4net.j
            var setup = new BridgeSetup(true);

            // setup Java classpath to find FOP libraries
            setup.AddAllJarsClassPath("lib");

            // we don't need to call back from Java
            setup.BindStatic = false;

            // now we create JVM and bind jni4net core
            Bridge.CreateJVM(setup);

            // now we bind all proxies of FOP objects
            // which are compiled in this assembly
            Bridge.RegisterAssembly(typeof (Program).Assembly);

            const string inFileName = "data/jni4net.fo";
            const string outFileName = "data/jni4net.pdf";


            //Below is just plain Copy&Paste of FOP basic sample java code
            OutputStream output = null;
            try
            {
                // Step 1: Construct a FopFactory
                // (reuse if you plan to render multiple documents!)
                FopFactory fopFactory = FopFactory.newInstance();

                // Step 2: Set up output stream.
                output = new BufferedOutputStream(new FileOutputStream(new File(outFileName)));

                // Step 3: Construct fop with desired output format
                Fop fop = fopFactory.newFop(MimeConstants_.MIME_PDF, output);

                // Step 4: Setup JAXP using identity transformer
                TransformerFactory factory = TransformerFactory.newInstance();
                Transformer transformer = factory.newTransformer(); // identity transformer

                // Step 5: Setup input and output for XSLT transformation
                // Setup input stream
                Source src = new StreamSource(new File(inFileName));

                // Resulting SAX events (the generated FO) must be piped through to FOP
                Result res = new SAXResult(fop.getDefaultHandler());

                // Step 6: Start XSLT transformation and FOP processing
                transformer.transform(src, res);
            }
            finally
            {
                // Clean-up
                if (output != null)
                {
                    output.close();
                }
            }
        }
 public virtual void save(File file, Configuration config)
 {
   BufferedOutputStream bufferedOutputStream = new BufferedOutputStream((OutputStream) new FileOutputStream(file));
   this.save((OutputStream) bufferedOutputStream, config);
   ((FilterOutputStream) bufferedOutputStream).close();
 }
Ejemplo n.º 4
0
 public static void saveChartAsPNG(File file, JFreeChart chart, int width, int height, ChartRenderingInfo info)
 {
   if (file == null)
   {
     string str = "Null 'file' argument.";
     Throwable.__\u003CsuppressFillInStackTrace\u003E();
     throw new IllegalArgumentException(str);
   }
   else
   {
     BufferedOutputStream bufferedOutputStream = new BufferedOutputStream((OutputStream) new FileOutputStream(file));
     try
     {
       ChartUtilities.writeChartAsPNG((OutputStream) bufferedOutputStream, chart, width, height, info);
     }
     finally
     {
       ((OutputStream) bufferedOutputStream).close();
     }
   }
 }
Ejemplo n.º 5
0
    void InvokeFOP(string[] args)
    {
        bool dependent = org.apache.fop.cli.Main.checkDependencies();
        if (dependent)
        {
            org.apache.fop.cli.CommandLineOptions options = null;
            org.apache.fop.apps.FOUserAgent foUserAgent = null;
            java.io.OutputStream outx = null;

            try
            {
                options = new org.apache.fop.cli.CommandLineOptions();
                options.parse(args);

                Type options_type = typeof(org.apache.fop.cli.CommandLineOptions);
                System.Reflection.MethodInfo mi = options_type.GetMethod("getFOUserAgent",
                    System.Reflection.BindingFlags.Instance |
                    System.Reflection.BindingFlags.NonPublic);

                //foUserAgent = options.getFOUserAgent();
                foUserAgent = (org.apache.fop.apps.FOUserAgent)mi.Invoke(
                    options, new object[] { });

                mi = options_type.GetMethod("getOutputFormat",
                    System.Reflection.BindingFlags.Instance |
                    System.Reflection.BindingFlags.NonPublic);

                //String outputFormat = options.getOutputFormat();
                String outputFormat = (String)mi.Invoke(
                    options, new object[] { });

                try
                {
                    if (options.getOutputFile() != null)
                    {
                        outx = new java.io.BufferedOutputStream(
                            new java.io.FileOutputStream(options.getOutputFile()));
                        foUserAgent.setOutputFile(options.getOutputFile());
                    }

                    if (!org.apache.fop.apps.MimeConstants.__Fields.MIME_XSL_FO.Equals(outputFormat))
                    {
                        options.getInputHandler().renderTo(foUserAgent, outputFormat, outx);
                    }
                    else
                    {
                        options.getInputHandler().transformTo(outx);
                    }
                }
                finally
                {
                    org.apache.commons.io.IOUtils.closeQuietly(outx);
                }
            }
            catch (Exception ex)
            {
                if (options != null && options.getOutputFile() != null)
                {
                    options.getOutputFile().delete();
                }
                throw ex;
            }
        }
    }