Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void copyfile(String source, String destination) throws org.maltparser.core.exception.MaltChainedException
        public static void copyfile(string source, string destination)
        {
            try
            {
                sbyte[]              readBuffer = new sbyte[BUFFER];
                BufferedInputStream  bis        = new BufferedInputStream(new FileStream(source, FileMode.Open, FileAccess.Read));
                BufferedOutputStream bos        = new BufferedOutputStream(new FileStream(destination, FileMode.Create, FileAccess.Write), BUFFER);
                int n = 0;
                while ((n = bis.read(readBuffer, 0, BUFFER)) != -1)
                {
                    bos.write(readBuffer, 0, n);
                }
                bos.flush();
                bos.close();
                bis.close();
            }
            catch (FileNotFoundException e)
            {
                throw new MaltChainedException("The destination file '" + destination + "' cannot be created when coping the file. ", e);
            }
            catch (IOException e)
            {
                throw new MaltChainedException("The source file '" + source + "' cannot be copied to destination '" + destination + "'. ", e);
            }
        }
Ejemplo n.º 2
0
        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.º 3
0
        public virtual void AES256IGEDecrypt(string sourceFile, string destFile, byte[] iv, byte[] key)
        {
            int           num1;
            File          file   = new File(sourceFile);
            File          file2  = new File(destFile);
            AESFastEngine engine = new AESFastEngine();

            engine.init(false, new KeyParameter(key));
            byte[] buffer  = CryptoUtils.substring(iv, 0x10, 0x10);
            byte[] buffer2 = CryptoUtils.substring(iv, 0, 0x10);
            BufferedInputStream.__ <clinit>();
            BufferedInputStream  stream  = new BufferedInputStream(new FileInputStream(file));
            BufferedOutputStream stream2 = new BufferedOutputStream(new FileOutputStream(file2));

            byte[] buffer3 = new byte[0x10];
Label_0060:
            num1 = stream.read(buffer3);
            if (num1 <= 0)
            {
                stream2.flush();
                stream2.close();
                stream.close();
            }
            else
            {
                byte[] @in   = new byte[0x10];
                int    index = 0;
                while (true)
                {
                    if (index >= 0x10)
                    {
                        break;
                    }
                    @in[index] = (byte)((sbyte)(buffer3[index] ^ buffer[index]));
                    index++;
                }
                engine.processBlock(@in, 0, @in, 0);
                index = 0;
                while (true)
                {
                    if (index >= 0x10)
                    {
                        break;
                    }
                    @in[index] = (byte)((sbyte)(@in[index] ^ buffer2[index]));
                    index++;
                }
                buffer2 = buffer3;
                buffer  = @in;
                buffer3 = new byte[0x10];
                stream2.write(@in);
                goto Label_0060;
            }
        }
Ejemplo n.º 4
0
        public virtual void saveModel(string filename)
        {
            FileOutputStream     fileOutputStream     = new FileOutputStream(filename);
            BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(fileOutputStream);
            ObjectOutputStream   objectOutputStream   = new ObjectOutputStream(bufferedOutputStream);

            this.writeFst(objectOutputStream);
            objectOutputStream.flush();
            objectOutputStream.close();
            bufferedOutputStream.close();
            fileOutputStream.close();
        }
Ejemplo n.º 5
0
        public static void GeneratePdf(string foFile, string pdfFile)
        {
            OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(new java.io.File(pdfFile)));

            try
            {
                FopFactory fopFactory = FopFactory.newInstance(new java.net.URI("."));
                Fop        fop        = fopFactory.newFop("application/pdf", outputStream);
                javax.xml.transform.TransformerFactory factory     = javax.xml.transform.TransformerFactory.newInstance();
                javax.xml.transform.Transformer        transformer = factory.newTransformer();
                javax.xml.transform.Source             source      = new javax.xml.transform.stream.StreamSource(new java.io.File(foFile));
                javax.xml.transform.Result             result      = new javax.xml.transform.sax.SAXResult(fop.getDefaultHandler());
                transformer.transform(source, result);
            }

            finally
            {
                outputStream.close();
            }
        }
Ejemplo n.º 6
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();
                }
            }
        }