Inheritance: java.io.FilterInputStream
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
 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;
 }
 public virtual void load(InputStream @in)
 {
   if (@in == null)
   {
     Throwable.__\u003CsuppressFillInStackTrace\u003E();
     throw new NullPointerException();
   }
   else
   {
     IOException ioException;
     try
     {
       BufferedInputStream bufferedInputStream = new BufferedInputStream(@in);
       Properties properties = new Properties();
       properties.load((InputStream) bufferedInputStream);
       ((Hashtable) this.getConfiguration()).putAll((Map) properties);
       bufferedInputStream.close();
       return;
     }
     catch (IOException ex)
     {
       int num = 1;
       ioException = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num);
     }
     Log.warn((object) "Unable to read configuration", (Exception) ioException);
   }
 }
        /// <summary>
        /// Train a Stanford NER model from a configuration file
        /// </summary>
        /// <param name="prop">Configuration file</param>
        public bool Train(string prop)
        {
            try
            {
                java.util.Properties props = new java.util.Properties();
                InputStream st = new BufferedInputStream(new FileInputStream(prop));
                InputStreamReader reader = new InputStreamReader(st, "utf-8");
                props.load(reader);
                _crfModel = new CRFClassifier(props);

                _crfModel.train();
                String serializeTo = _crfModel.flags.serializeTo;
                if (serializeTo != null)
                {
                    _crfModel.serializeClassifier(serializeTo);
                }

                return true;
            }
            catch (Exception e)
            {
                System.Console.WriteLine("Unable to train the Standford CRF model" + e.ToString());
                return false;

            }
        }