private static sbyte[] readFile(Jfile file)
        {
            InputStream @in = new BufferedInputStream(new FileInputStream(file));

            ByteArrayOutputStream bytes = new ByteArrayOutputStream(new FileStream(file.Name, FileMode.Open));

            try
            {
                sbyte[] buffer = new sbyte[1024];
                int     length;
                while ((length = @in.read(buffer, 0, buffer.Length)) > 0)
                {
                    bytes.write(buffer, 0, length);
                }
            }
            finally
            {
                try
                {
                    @in.close();
                }
                catch (IOException)
                {
                    // sorry that this can fail!
                }
            }

            return(bytes.toSbyteArray());
        }
Esempio n. 2
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);
            }
        }
Esempio n. 3
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();
            }
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
0
        public static byte[] getBytesFromFileJava(string filePath)
        {
            FileInputStream     fis = new FileInputStream(new java.io.File(filePath));
            BufferedInputStream bis = new BufferedInputStream(fis);
            int numByte             = bis.available();

            byte[] buff = new byte[numByte];
            bis.read(buff, 0, numByte);
            bis.close();
            fis.close();
            return(buff);
        }
Esempio n. 6
0
        /// <summary>
        /// Reads a jar file entry into a byte array.
        /// </summary>
        /// <param name="jis"> The jar input stream </param>
        /// <param name="jarName"> The name of a jar file entry </param>
        /// <exception cref="PluginException"> </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void loadClassBytes(java.util.jar.JarInputStream jis, String jarName) throws org.maltparser.core.exception.MaltChainedException
        private void loadClassBytes(JarInputStream jis, string jarName)
        {
            BufferedInputStream jarBuf = new BufferedInputStream(jis);
            MemoryStream        jarOut = new MemoryStream();
            int b;

            try
            {
                while ((b = jarBuf.read()) != -1)
                {
                    jarOut.WriteByte(b);
                }
                classByteArrays[jarName.Substring(0, jarName.Length - 6)] = jarOut.toByteArray();
            }
            catch (IOException e)
            {
                throw new PluginException("Error reading entry " + jarName + ". ", e);
            }
        }
Esempio n. 7
0
        public static string readClasspathResourceAsString(string resourceName)
        {
            Stream resourceAsStream = typeof(IoUtil).ClassLoader.getResourceAsStream(resourceName);

            if (resourceAsStream == null)
            {
                throw new ProcessEngineException("resource " + resourceName + " not found");
            }

            MemoryStream outStream = new MemoryStream();

            int next;

            sbyte[] result;
            sbyte[] buffer = new sbyte[1024];

            BufferedInputStream inputStream = null;

            try
            {
                inputStream = new BufferedInputStream(resourceAsStream);
                while ((next = inputStream.read(buffer)) >= 0)
                {
                    outStream.Write(buffer, 0, next);
                }

                result = outStream.toByteArray();
            }
            catch (Exception e)
            {
                throw LOG.exceptionWhileReadingFile(resourceName, e);
            }
            finally
            {
                IoUtil.closeSilently(inputStream);
                IoUtil.closeSilently(outStream);
            }
            return(StringHelper.NewString(result, Charset.forName("UTF-8")));
        }
Esempio n. 8
0
        public virtual void run()
        {
            Socket socket = this.socket;

            try
            {
                if (bis == null)
                {
                    bis = new BufferedInputStream(socket.InputStream);
                }
                long offset = -1;

                ExtendedDataInput @in = null;         //isRemoteLittleEndian ? new LittleEndianDataInputStream(bis) : new BigEndianDataInputStream(bis);

                while (true)
                {
                    if (@in == null)
                    {
                        bool?b = bis.read() != 0;                  //true/false : little/big
                        if (b == true)
                        {
                            @in = new LittleEndianDataInputStream(bis);
                        }
                        else
                        {
                            @in = new BigEndianDataInputStream(bis);
                        }
                    }
                    else
                    {
                        @in.readBoolean();
                    }
                    long msgid = @in.readLong();
                    if (offset == -1)
                    {
                        offset = msgid;
                    }
                    else
                    {
                        assert(offset == msgid);
                    }
                    string topic = @in.readString();

                    short         flag    = @in.readShort();
                    EntityFactory factory = new BasicEntityFactory();
                    int           form    = flag >> 8;

                    int type = flag & 0xff;

                    if (form < 0 || form > MAX_FORM_VALUE)
                    {
                        throw new IOException("Invalid form value: " + form);
                    }
                    if (type < 0 || type > MAX_TYPE_VALUE)
                    {
                        throw new IOException("Invalid type value: " + type);
                    }
                    Entity_DATA_FORM df = Enum.GetValues(typeof(Entity_DATA_FORM))[form];
                    Entity_DATA_TYPE dt = Enum.GetValues(typeof(Entity_DATA_TYPE))[type];
                    Entity           body;
                    try
                    {
                        body = factory.createEntity(df, dt, @in);
                    }
                    catch (Exception exception)
                    {
                        throw exception;
                    }
                    if (body.Vector)
                    {
                        BasicAnyVector dTable = (BasicAnyVector)body;

                        int colSize = dTable.rows();
                        int rowSize = dTable.getEntity(0).rows();

                        if (rowSize >= 1)
                        {
                            if (rowSize == 1)
                            {
                                BasicMessage rec = new BasicMessage(msgid, topic, dTable);
                                dispatcher.dispatch(rec);
                            }
                            else
                            {
                                IList <IMessage> messages = new List <IMessage>(rowSize);
                                for (int i = 0; i < rowSize; i++)
                                {
                                    BasicAnyVector row = new BasicAnyVector(colSize);

                                    for (int j = 0; j < colSize; j++)
                                    {
                                        AbstractVector vector = (AbstractVector)dTable.getEntity(j);
                                        Entity         entity = vector.get(i);
                                        row.setEntity(j, entity);
                                    }
                                    BasicMessage rec = new BasicMessage(msgid, topic, row);
                                    messages.Add(rec);
                                    msgid++;
                                }
                                dispatcher.batchDispatch(messages);
                            }
                        }
                        offset += rowSize;
                    }
                    else
                    {
                        throw new Exception("message body has an invalid format.vector is expected");
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.Write(e.StackTrace);
            }
            finally
            {
                try
                {
                    socket.close();
                }
                catch (IOException e)
                {
                    Console.WriteLine(e.ToString());
                    Console.Write(e.StackTrace);
                }
            }
        }