コード例 #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void writeArcViewFile(String instrfile, String outstrfile, String[] new_comments) throws java.io.IOException
        public virtual void writeArcViewFile(string instrfile, string outstrfile, string[] new_comments)
        {
            string      rtn  = "StateMod_DeltaPlot.writeArcViewFile";
            PrintWriter @out = null;

            if (Message.isDebugOn)
            {
                Message.printDebug(2, rtn, "in writeArcViewFile printing file: " + outstrfile);
            }
            try
            {
                @out = new PrintWriter(new FileStream(outstrfile, FileMode.Create, FileAccess.Write));
                this.writeArcViewFile(@out);
                @out.flush();
                @out.close();
                @out = null;
                rtn  = null;
            }
            catch (Exception e)
            {
                if (@out != null)
                {
                    @out.close();
                }
                @out = null;
                rtn  = null;
                Message.printWarning(2, rtn, e);
                throw new IOException(e.Message);
            }
        }
コード例 #2
0
        public virtual void dumpDot(PrintWriter @out)
        {
            @out.write("digraph \"CART Tree\" {\n");
            @out.write("rankdir = LR\n");
            DecisionTree.Node[] array = this.cart;
            int num = array.Length;

            for (int i = 0; i < num; i++)
            {
                DecisionTree.Node node = array[i];
                @out.println(new StringBuilder().append("\t\"node").append(Object.instancehelper_hashCode(node)).append("\" [ label=\"").append(Object.instancehelper_toString(node)).append("\", color=").append(this.dumpDotNodeColor(node)).append(", shape=").append(this.dumpDotNodeShape(node)).append(" ]\n").toString());
                if (node is DecisionTree.DecisionNode)
                {
                    DecisionTree.DecisionNode decisionNode = (DecisionTree.DecisionNode)node;
                    if (decisionNode.qtrue < this.cart.Length && this.cart[decisionNode.qtrue] != null)
                    {
                        @out.write(new StringBuilder().append("\t\"node").append(Object.instancehelper_hashCode(node)).append("\" -> \"node").append(Object.instancehelper_hashCode(this.cart[decisionNode.qtrue])).append("\" [ label=TRUE ]\n").toString());
                    }
                    if (decisionNode.qfalse < this.cart.Length && this.cart[decisionNode.qfalse] != null)
                    {
                        @out.write(new StringBuilder().append("\t\"node").append(Object.instancehelper_hashCode(node)).append("\" -> \"node").append(Object.instancehelper_hashCode(this.cart[decisionNode.qfalse])).append("\" [ label=FALSE ]\n").toString());
                    }
                }
            }
            @out.write("}\n");
            @out.close();
        }
コード例 #3
0
        /// <summary>
        /// Write a list of StateCU_ClimateStation to a file.  The filename is adjusted
        /// to the working directory if necessary using IOUtil.getPathUsingWorkingDir(). </summary>
        /// <param name="filenamePrev"> The name of the previous version of the file (for processing headers).
        /// Specify as null if no previous file is available. </param>
        /// <param name="filename"> The name of the file to write. </param>
        /// <param name="dataList"> A list of StateCU_ClimateStation to write. </param>
        /// <param name="newComments"> Comments to add to the top of the file.  Specify as null if no comments are available. </param>
        /// <exception cref="IOException"> if there is an error writing the file. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeStateCUFile(String filenamePrev, String filename, java.util.List<StateCU_ClimateStation> dataList, java.util.List<String> newComments) throws java.io.IOException
        public static void writeStateCUFile(string filenamePrev, string filename, IList <StateCU_ClimateStation> dataList, IList <string> newComments)
        {
            IList <string> comment_str = new List <string>(1);

            comment_str.Add("#");
            IList <string> ignore_comment_str = new List <string>(1);

            ignore_comment_str.Add("#>");
            PrintWriter @out = null;

            try
            {
                string full_filename_prev = IOUtil.getPathUsingWorkingDir(filenamePrev);
                string full_filename      = IOUtil.getPathUsingWorkingDir(filename);
                @out = IOUtil.processFileHeaders(full_filename_prev, full_filename, newComments, comment_str, ignore_comment_str, 0);
                if (@out == null)
                {
                    throw new IOException("Error writing to \"" + full_filename + "\"");
                }
                writeStateCUFile(dataList, @out);
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
コード例 #4
0
ファイル: Convert.cs プロジェクト: yyl-20020115/Sphinx4CSharp
        private static void exportFst(Fst fst, string text)
        {
            FileWriter  fileWriter  = new FileWriter(text);
            PrintWriter printWriter = new PrintWriter(fileWriter);
            State       start       = fst.getStart();

            printWriter.println(new StringBuilder().append(start.getId()).append("\t").append(start.getFinalWeight()).toString());
            int numStates = fst.getNumStates();

            for (int i = 0; i < numStates; i++)
            {
                State state = fst.getState(i);
                if (state.getId() != fst.getStart().getId())
                {
                    printWriter.println(new StringBuilder().append(state.getId()).append("\t").append(state.getFinalWeight()).toString());
                }
            }
            string[] isyms = fst.getIsyms();
            string[] osyms = fst.getOsyms();
            numStates = fst.getNumStates();
            for (int j = 0; j < numStates; j++)
            {
                State state2  = fst.getState(j);
                int   numArcs = state2.getNumArcs();
                for (int k = 0; k < numArcs; k++)
                {
                    Arc    arc   = state2.getArc(k);
                    string text2 = (isyms == null) ? Integer.toString(arc.getIlabel()) : isyms[arc.getIlabel()];
                    string text3 = (osyms == null) ? Integer.toString(arc.getOlabel()) : osyms[arc.getOlabel()];
                    printWriter.println(new StringBuilder().append(state2.getId()).append("\t").append(arc.getNextState().getId()).append("\t").append(text2).append("\t").append(text3).append("\t").append(arc.getWeight()).toString());
                }
            }
            printWriter.close();
        }
コード例 #5
0
 public virtual void save(string name)
 {
     try
     {
         PrintWriter printWriter = new PrintWriter(new FileWriter(name));
         printWriter.println(new StringBuilder().append(this.ngauss).append(" ").append(this.ncoefs).toString());
         for (int i = 0; i < this.ngauss; i++)
         {
             printWriter.println(new StringBuilder().append("gauss ").append(i).append(' ').append(this.getWeight(i)).toString());
             for (int j = 0; j < this.ncoefs; j++)
             {
                 printWriter.print(new StringBuilder().append(this.means[i][j]).append(" ").toString());
             }
             printWriter.println();
             for (int j = 0; j < this.ncoefs; j++)
             {
                 printWriter.print(new StringBuilder().append(this.getVar(i, j)).append(" ").toString());
             }
             printWriter.println();
         }
         printWriter.println(this.nT);
         printWriter.close();
     }
     catch (IOException ex)
     {
         Throwable.instancehelper_printStackTrace(ex);
     }
 }
コード例 #6
0
        public virtual void store(string filePath, int index)
        {
            PrintWriter printWriter = new PrintWriter(filePath, "UTF-8");

            printWriter.println("1");
            printWriter.println(this.loader.getNumStreams());
            for (int i = 0; i < this.loader.getNumStreams(); i++)
            {
                printWriter.println(this.loader.getVectorLength()[i]);
                for (int j = 0; j < this.loader.getVectorLength()[i]; j++)
                {
                    for (int k = 0; k < this.loader.getVectorLength()[i]; k++)
                    {
                        printWriter.print(this.As[index][i][j][k]);
                        printWriter.print(" ");
                    }
                    printWriter.println();
                }
                for (int j = 0; j < this.loader.getVectorLength()[i]; j++)
                {
                    printWriter.print(this.Bs[index][i][j]);
                    printWriter.print(" ");
                }
                printWriter.println();
                for (int j = 0; j < this.loader.getVectorLength()[i]; j++)
                {
                    printWriter.print("1.0 ");
                }
                printWriter.println();
            }
            printWriter.close();
        }
コード例 #7
0
ファイル: PdfboxComponent.cs プロジェクト: wingfay/studio
 public void ToTxt(string absoluteFilePath, string outputPath)
 {
     using (PDDocument pdf = PDDocument.load(new java.io.File(absoluteFilePath)))
     {
         Writer output = new PrintWriter(outputPath, "utf-8");
         //new PDFDomTree().writeText(pdf, output);
         output.close();
     }
 }
コード例 #8
0
        /// <summary>
        /// Exports a list of strings to a file. </summary>
        /// <param name="filename"> the name of the file to write. </param>
        /// <param name="strings"> a non-null Vector of Strings, each element of which will be
        /// another line in the file. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void export(String filename, java.util.List<String> strings) throws Exception
        protected internal virtual void export(string filename, IList <string> strings)
        {
            string routine = "StateMod_Data_JFrame.export";

            // First see if we can write the file given the security
            // settings...
            if (!SecurityCheck.canWriteFile(filename))
            {
                Message.printWarning(1, routine, "Cannot save \"" + filename + "\".");
                throw new Exception("Security check failed - unable to write \"" + filename + "\"");
            }

            JGUIUtil.setWaitCursor(this, true);

            // Create a new FileOutputStream wrapped with a DataOutputStream
            // for writing to a file.
            PrintWriter oStream = null;

            try
            {
                oStream = new PrintWriter(new StreamWriter(filename));
            }
            catch (Exception)
            {
                JGUIUtil.setWaitCursor(this, false);
                throw new Exception("Error opening file \"" + filename + "\".");
            }

            try
            {
                // Write each element of the strings Vector to a file.
                // For some reason, when just using println in an
                // applet, the cr-nl pair is not output like it should
                // be on Windows95.  Java Bug???
                string linesep = System.getProperty("line.separator");
                int    size    = strings.Count;
                for (int i = 0; i < size; i++)
                {
                    oStream.print(strings[i].ToString() + linesep);
                }
                oStream.flush();
                oStream.close();
            }
            catch (Exception)
            {
                JGUIUtil.setWaitCursor(this, false);
                throw new Exception("Error writing to file \"" + filename + "\".");
            }

            JGUIUtil.setWaitCursor(this, false);
        }
コード例 #9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public void dumpIndexFile(String filename) throws java.io.IOException, java.io.FileNotFoundException
        public virtual void dumpIndexFile(string filename)
        {
            PrintWriter @out = new PrintWriter(new System.IO.FileStream(filename, System.IO.FileMode.Create, System.IO.FileAccess.Write));

            @out.println("  Start    Size       Name");
            string[] files     = listDirectory("");
            long     totalSize = dumpIndexRecursive(@out, "", files);
            long     imageSize = ((long)numSectors) * sectorLength;

            @out.println(string.Format("Total Size {0,10:D}", totalSize));
            @out.println(string.Format("Image Size {0,10:D}", imageSize));
            @out.println(string.Format("Missing    {0,10:D} ({1:D} sectors)", imageSize - totalSize, numSectors - (totalSize / sectorLength)));
            @out.close();
        }
コード例 #10
0
 public virtual void close()
 {
     try
     {
         this.Println(FrameType.CLOSE.ToString());
         @in.Close();
         @out.close();
         socket.Close();
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex.ToString());
         Console.Write(ex.StackTrace);
     }
 }
コード例 #11
0
ファイル: Convert.cs プロジェクト: yyl-20020115/Sphinx4CSharp
        private static void exportSymbols(string[] array, string text)
        {
            if (array == null)
            {
                return;
            }
            FileWriter  fileWriter  = new FileWriter(text);
            PrintWriter printWriter = new PrintWriter(fileWriter);

            for (int i = 0; i < array.Length; i++)
            {
                string text2 = array[i];
                printWriter.println(new StringBuilder().append(text2).append("\t").append(i).toString());
            }
            printWriter.close();
        }
コード例 #12
0
 public virtual void dumpDot(string path)
 {
     try
     {
         PrintWriter printWriter = new PrintWriter(new FileOutputStream(path));
         printWriter.println(new StringBuilder().append("digraph \"").append(path).append("\" {").toString());
         printWriter.println("rankdir = LR\n");
         this.traverseDot(printWriter, new HashSet());
         printWriter.println("}");
         printWriter.close();
     }
     catch (FileNotFoundException ex)
     {
         [email protected](new StringBuilder().append("Can't write to ").append(path).append(' ').append(ex).toString());
     }
     return;
 }
コード例 #13
0
 public virtual void saveHTK(string nomFich, string nomHMM, string parmKind)
 {
     try
     {
         PrintWriter printWriter = new PrintWriter(new FileWriter(nomFich));
         printWriter.println("~o");
         printWriter.println("<HMMSETID> tree");
         printWriter.println(new StringBuilder().append("<STREAMINFO> 1 ").append(this.getNcoefs()).toString());
         printWriter.println(new StringBuilder().append("<VECSIZE> ").append(this.getNcoefs()).append("<NULLD>").append(parmKind).append("<DIAGC>").toString());
         printWriter.println("~r \"rtree_1\"");
         printWriter.println("<REGTREE> 1");
         printWriter.println(new StringBuilder().append("<TNODE> 1 ").append(this.getNgauss()).toString());
         printWriter.println(new StringBuilder().append("~h \"").append(nomHMM).append('"').toString());
         printWriter.println("<BEGINHMM>");
         printWriter.println("<NUMSTATES> 3");
         printWriter.println("<STATE> 2");
         printWriter.println(new StringBuilder().append("<NUMMIXES> ").append(this.getNgauss()).toString());
         for (int i = 1; i <= this.getNgauss(); i++)
         {
             printWriter.println(new StringBuilder().append("<MIXTURE> ").append(i).append(' ').append(this.getWeight(i - 1)).toString());
             printWriter.println("<RCLASS> 1");
             printWriter.println(new StringBuilder().append("<MEAN> ").append(this.getNcoefs()).toString());
             for (int j = 0; j < this.getNcoefs(); j++)
             {
                 printWriter.print(new StringBuilder().append(this.getMean(i - 1, j)).append(" ").toString());
             }
             printWriter.println();
             printWriter.println(new StringBuilder().append("<VARIANCE> ").append(this.getNcoefs()).toString());
             for (int j = 0; j < this.getNcoefs(); j++)
             {
                 printWriter.print(new StringBuilder().append(this.getVar(i - 1, j)).append(" ").toString());
             }
             printWriter.println();
         }
         printWriter.println("<TRANSP> 3");
         printWriter.println("0 1 0");
         printWriter.println("0 0.7 0.3");
         printWriter.println("0 0 0");
         printWriter.println("<ENDHMM>");
         printWriter.close();
     }
     catch (IOException ex)
     {
         Throwable.instancehelper_printStackTrace(ex);
     }
 }
コード例 #14
0
        internal virtual void convertMMF(string text)
        {
            IOException ex2;

            try
            {
                BufferedReader bufferedReader = new BufferedReader(new FileReader(text));
                PrintWriter    printWriter    = new PrintWriter(new FileWriter(new StringBuilder().append(text).append(".conv").toString()));
                for (;;)
                {
                    string text2 = bufferedReader.readLine();
                    if (text2 == null)
                    {
                        break;
                    }
                    int num = String.instancehelper_indexOf(text2, "~h");
                    if (num >= 0)
                    {
                        num = String.instancehelper_indexOf(text2, 34);
                        int    num2  = String.instancehelper_lastIndexOf(text2, 34);
                        string text3 = String.instancehelper_substring(text2, num + 1, num2);
                        this.split3ph(text3);
                        string text4 = this.conv3ph();
                        printWriter.println(new StringBuilder().append("~h \"").append(text4).append('"').toString());
                    }
                    else
                    {
                        printWriter.println(text2);
                    }
                }
                printWriter.close();
                bufferedReader.close();
            }
            catch (IOException ex)
            {
                ex2 = ex;
                goto IL_D2;
            }
            return;

IL_D2:
            IOException ex3 = ex2;

            Throwable.instancehelper_printStackTrace(ex3);
        }
コード例 #15
0
        private void saveWhiteList()
        {
            try
            {
                var    printwriter = new PrintWriter(new FileWriter(whitelistPlayersFile, false));
                string s;
                for (Iterator iterator = whiteListedIPs.iterator(); iterator.hasNext(); printwriter.println(s))
                {
                    s = (string)iterator.next();
                }

                printwriter.close();
            }
            catch (Exception exception)
            {
                logger.warning((new StringBuilder()).append("Failed to save white-list: ").append(exception).toString());
            }
        }
コード例 #16
0
        private void saveOps()
        {
            try
            {
                var    printwriter = new PrintWriter(new FileWriter(opFile, false));
                string s;
                for (Iterator iterator = ops.iterator(); iterator.hasNext(); printwriter.println(s))
                {
                    s = (string)iterator.next();
                }

                printwriter.close();
            }
            catch (Exception exception)
            {
                logger.warning((new StringBuilder()).append("Failed to save ip ban list: ").append(exception).toString());
            }
        }
コード例 #17
0
        /// <summary>
        /// this test compares search results when using and not using compound
        ///  files.
        /// 
        ///  TODO: There is rudimentary search result validation as well, but it is
        ///        simply based on asserting the output observed in the old test case,
        ///        without really knowing if the output is correct. Someone needs to
        ///        validate this output and make any changes to the checkHits method.
        /// </summary>
        public virtual void TestRun()
        {
            StringWriter sw = new StringWriter();
              PrintWriter pw = new PrintWriter(sw, true);
              int MAX_DOCS = atLeast(225);
              DoTest(random(), pw, false, MAX_DOCS);
              pw.close();
              sw.close();
              string multiFileOutput = sw.ToString();
              //System.out.println(multiFileOutput);

              sw = new StringWriter();
              pw = new PrintWriter(sw, true);
              DoTest(random(), pw, true, MAX_DOCS);
              pw.close();
              sw.close();
              string singleFileOutput = sw.ToString();

              Assert.AreEqual(multiFileOutput, singleFileOutput);
        }
コード例 #18
0
        public static void Main(string[] args)
        {
            PrintWriter @out =
                new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(args[1]))));
            DataInputStream @in = new DataInputStream(new GZIPInputStream(new FileInputStream(args[0])));

            double d;

            try
            {
                while (true)
                {
                    @out.println(@in.readDouble());
                }
            }
            catch (Exception)
            {
            }
            @out.close();
            @in.close();
        }
コード例 #19
0
        /// <summary>
        /// this test performs a number of searches. It also compares output
        ///  of searches using multi-file index segments with single-file
        ///  index segments.
        ///
        ///  TODO: someone should check that the results of the searches are
        ///        still correct by adding assert statements. Right now, the test
        ///        passes if the results are the same between multi-file and
        ///        single-file formats, even if the results are wrong.
        /// </summary>
        public virtual void TestSearch()
        {
            StringWriter sw = new StringWriter();
            PrintWriter  pw = new PrintWriter(sw, true);

            DoTestSearch(random(), pw, false);
            pw.close();
            sw.close();
            string multiFileOutput = sw.ToString();

            //System.out.println(multiFileOutput);

            sw = new StringWriter();
            pw = new PrintWriter(sw, true);
            DoTestSearch(random(), pw, true);
            pw.close();
            sw.close();
            string singleFileOutput = sw.ToString();

            Assert.AreEqual(multiFileOutput, singleFileOutput);
        }
コード例 #20
0
        /// <summary>
        /// Write a list of StateCU_BlaneyCriddle to a file.  The filename is adjusted to
        /// the working directory if necessary using IOUtil.getPathUsingWorkingDir(). </summary>
        /// <param name="filename_prev"> The name of the previous version of the file (for
        /// processing headers).  Specify as null if no previous file is available. </param>
        /// <param name="filename"> The name of the file to write. </param>
        /// <param name="data_Vector"> A list of StateCU_BlaneyCriddle to write. </param>
        /// <param name="new_comments"> Comments to add to the top of the file.  Specify as null
        /// if no comments are available. </param>
        /// <param name="props"> Properties to control the output.  Currently only the
        /// optional Precision property can be set, indicating how many digits after the
        /// decimal should be printed (default is 3). </param>
        /// <exception cref="IOException"> if there is an error writing the file. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeStateCUFile(String filename_prev, String filename, java.util.List<StateCU_BlaneyCriddle> data_Vector, java.util.List<String> new_comments, RTi.Util.IO.PropList props) throws java.io.IOException
        public static void writeStateCUFile(string filename_prev, string filename, IList <StateCU_BlaneyCriddle> data_Vector, IList <string> new_comments, PropList props)
        {
            IList <string> comment_str = new List <string>(1);

            comment_str.Add("#");
            IList <string> ignore_comment_str = new List <string>(1);

            ignore_comment_str.Add("#>");
            PrintWriter @out = null;
            string      full_filename_prev = IOUtil.getPathUsingWorkingDir(filename_prev);
            string      full_filename      = IOUtil.getPathUsingWorkingDir(filename);

            @out = IOUtil.processFileHeaders(full_filename_prev, full_filename, new_comments, comment_str, ignore_comment_str, 0);
            if (@out == null)
            {
                throw new IOException("Error writing to \"" + full_filename + "\"");
            }
            writeVector(data_Vector, @out, props);
            @out.flush();
            @out.close();
            @out = null;
        }
コード例 #21
0
        /// <summary>
        /// this test compares search results when using and not using compound
        ///  files.
        ///
        ///  TODO: There is rudimentary search result validation as well, but it is
        ///        simply based on asserting the output observed in the old test case,
        ///        without really knowing if the output is correct. Someone needs to
        ///        validate this output and make any changes to the checkHits method.
        /// </summary>
        public virtual void TestRun()
        {
            StringWriter sw       = new StringWriter();
            PrintWriter  pw       = new PrintWriter(sw, true);
            int          MAX_DOCS = atLeast(225);

            DoTest(random(), pw, false, MAX_DOCS);
            pw.close();
            sw.close();
            string multiFileOutput = sw.ToString();

            //System.out.println(multiFileOutput);

            sw = new StringWriter();
            pw = new PrintWriter(sw, true);
            DoTest(random(), pw, true, MAX_DOCS);
            pw.close();
            sw.close();
            string singleFileOutput = sw.ToString();

            Assert.AreEqual(multiFileOutput, singleFileOutput);
        }
コード例 #22
0
ファイル: Grammar.cs プロジェクト: yyl-20020115/Sphinx4CSharp
 public virtual void dumpRandomSentences(string path, int count)
 {
     try
     {
         HashSet     hashSet     = new HashSet();
         PrintWriter printWriter = new PrintWriter(new FileOutputStream(path));
         for (int i = 0; i < count; i++)
         {
             string randomSentence = this.getRandomSentence();
             if (!hashSet.contains(randomSentence))
             {
                 hashSet.add(randomSentence);
                 printWriter.println(randomSentence);
             }
         }
         printWriter.close();
     }
     catch (IOException ex)
     {
         this.logger.severe(new StringBuilder().append("Can't write random sentences to ").append(path).append(' ').append(ex).toString());
     }
 }
コード例 #23
0
 public static void save(ConfigurationManager cm, File cmLocation)
 {
     if (!String.instancehelper_endsWith(cmLocation.getName(), ".sxl"))
     {
         java.lang.System.err.println("WARNING: Serialized s4-configuration should have the suffix '.sxl'");
     }
     if (!ConfigurationManagerUtils.assertionsDisabled && cm == null)
     {
         throw new AssertionError();
     }
     try
     {
         PrintWriter printWriter = new PrintWriter(new OutputStreamWriter(new FileOutputStream(cmLocation), Charset.forName("UTF-8")));
         string      text        = ConfigurationManagerUtils.toXML(cm);
         printWriter.print(text);
         printWriter.flush();
         printWriter.close();
     }
     catch (FileNotFoundException ex)
     {
         Throwable.instancehelper_printStackTrace(ex);
     }
 }
コード例 #24
0
 public virtual void dumpGDL(string path)
 {
     try
     {
         try
         {
             PrintWriter printWriter = new PrintWriter(new FileOutputStream(path));
             printWriter.println("graph: {");
             printWriter.println("    orientation: left_to_right");
             printWriter.println("    layout_algorithm: dfs");
             this.traverseGDL(printWriter, new HashSet());
             printWriter.println("}");
             printWriter.close();
         }
         catch (FileNotFoundException ex)
         {
             [email protected](new StringBuilder().append("Can't write to ").append(path).append(' ').append(ex).toString());
         }
     }
     catch (IOException ex3)
     {
         [email protected](new StringBuilder().append("Trouble writing to ").append(path).append(' ').append(ex3).toString());
     }
 }
コード例 #25
0
ファイル: TestSearch.cs プロジェクト: Cefa68000/lucenenet
        /// <summary>
        /// this test performs a number of searches. It also compares output
        ///  of searches using multi-file index segments with single-file
        ///  index segments.
        /// 
        ///  TODO: someone should check that the results of the searches are
        ///        still correct by adding assert statements. Right now, the test
        ///        passes if the results are the same between multi-file and
        ///        single-file formats, even if the results are wrong.
        /// </summary>
        public virtual void TestSearch()
        {
            StringWriter sw = new StringWriter();
              PrintWriter pw = new PrintWriter(sw, true);
              DoTestSearch(random(), pw, false);
              pw.close();
              sw.close();
              string multiFileOutput = sw.ToString();
              //System.out.println(multiFileOutput);

              sw = new StringWriter();
              pw = new PrintWriter(sw, true);
              DoTestSearch(random(), pw, true);
              pw.close();
              sw.close();
              string singleFileOutput = sw.ToString();

              Assert.AreEqual(multiFileOutput, singleFileOutput);
        }
コード例 #26
0
        /// <summary>
        /// Writes a list of StateCU_ClimateStation objects to a list file.  A header is
        /// printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current </param>
        /// header (true) or to create a new file with a new header<param name="data"> the Vector of objects to write. </param>
        /// <param name="outputComments"> Comments to add to the header, usually the command file and database information. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateCU_ClimateStation> data, java.util.List<String> outputComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_ClimateStation> data, IList <string> outputComments)
        {
            int size = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ID");
            fields.Add("Name");
            fields.Add("Latitude");
            fields.Add("Elevation");
            fields.Add("Region1");
            fields.Add("Region2");
            fields.Add("HeightHumidity");
            fields.Add("HeightWind");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_CLIMATE_STATIONS;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateCU_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateCU_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int                    j             = 0;
            PrintWriter            @out          = null;
            StateCU_ClimateStation cli           = null;
            IList <string>         commentString = new List <string>(1);

            commentString.Add("#");
            IList <string> ignoreCommentString = new List <string>(1);

            ignoreCommentString.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (outputComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(outputComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateCU climate stations as a delimited list file.");
                newComments2.Insert(2, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentString, ignoreCommentString, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    buffer.Append("\"" + names[i] + "\"");
                    if (i < (fieldCount - 1))
                    {
                        buffer.Append(delimiter);
                    }
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    cli = data[i];

                    line[0] = StringUtil.formatString(cli.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(cli.getName(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(cli.getLatitude(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(cli.getElevation(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(cli.getRegion1(), formats[4]).Trim();
                    line[5] = StringUtil.formatString(cli.getRegion2(), formats[5]).Trim();
                    line[6] = StringUtil.formatString(cli.getZh(), formats[6]).Trim();
                    line[7] = StringUtil.formatString(cli.getZm(), formats[7]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                        if (j < (fieldCount - 1))
                        {
                            buffer.Append(delimiter);
                        }
                    }

                    @out.println(buffer.ToString());
                }
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
コード例 #27
0
        /// <summary>
        /// Writes a list of StateMod_RiverNetworkNode objects to a list file.  A header
        /// is printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the list of objects to write. </param>
        /// <param name="newComments"> new comments to add to the file header. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateMod_RiverNetworkNode> data, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_RiverNetworkNode> data, IList <string> newComments)
        {
            string routine = "StateMod_RiverNetworkNode.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ID");
            fields.Add("Name");
            fields.Add("DownstreamID");
            fields.Add("Comment");
            fields.Add("GWMaxRecharge");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateMod_DataSet.COMP_RIVER_NETWORK;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = fields[i];
                names[i]   = StateMod_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int         j    = 0;
            PrintWriter @out = null;
            StateMod_RiverNetworkNode rnn = null;

            string[]       line = new string[fieldCount];
            IList <string> commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  Do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (newComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(newComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateMod river network as a delimited list file.");
                newComments2.Insert(2, "See also the generalized network file.");
                newComments2.Insert(3, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    rnn = (StateMod_RiverNetworkNode)data[i];

                    line[0] = StringUtil.formatString(rnn.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(rnn.getName(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(rnn.getCstadn(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(rnn.getComment(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(rnn.getGwmaxr(), formats[4]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (j > 0)
                        {
                            buffer.Append(delimiter);
                        }
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                    }

                    @out.println(buffer.ToString());
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
コード例 #28
0
        /// <summary>
        /// Write the new (updated) river network file to the StateMod river network
        /// file.  If an original file is specified, then the original header is carried into the new file. </summary>
        /// <param name="infile"> Name of old file or null if no old file to update. </param>
        /// <param name="outfile"> Name of new file to create (can be the same as the old file). </param>
        /// <param name="theRivs"> list of StateMod_RiverNetworkNode to write. </param>
        /// <param name="newcomments"> New comments to write in the file header. </param>
        /// <param name="doWell"> Indicates whether well modeling fields should be written. </param>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeStateModFile(String infile, String outfile, java.util.List<StateMod_RiverNetworkNode> theRivs, java.util.List<String> newcomments, boolean doWell) throws Exception
        public static void writeStateModFile(string infile, string outfile, IList <StateMod_RiverNetworkNode> theRivs, IList <string> newcomments, bool doWell)
        {
            PrintWriter    @out = null;
            IList <string> commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            string routine = "StateMod_RiverNetworkNode.writeStateModFile";

            if (Message.isDebugOn)
            {
                Message.printDebug(2, routine, "Writing river network file \"" + outfile + "\" using \"" + infile + "\" header...");
            }

            try
            {
                // Process the header from the old file...
                @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(infile), IOUtil.getPathUsingWorkingDir(outfile), newcomments, commentIndicators, ignoredCommentIndicators, 0);

                string cmnt   = "#>";
                string iline  = null;
                string format = null;
                StateMod_RiverNetworkNode riv = null;

                @out.println(cmnt + " *******************************************************");
                @out.println(cmnt + "  StateMod River Network File");
                @out.println(cmnt + "  WARNING - if .net file is available, it should be edited and the .rin");
                @out.println(cmnt + "  file should be created from the .net");
                @out.println(cmnt);
                @out.println(cmnt + "  format:  (a12, a24, a12, 1x, a12, 1x, f8.0)");
                @out.println(cmnt);
                @out.println(cmnt + "  ID           cstaid:  Station ID");
                @out.println(cmnt + "  Name         stanam:  Station name");
                @out.println(cmnt + "  Downstream   cstadn:  Downstream node ID");
                @out.println(cmnt + "  Comment     comment:  Alternate identifier/comment.");
                @out.println(cmnt + "  GWMax        gwmaxr:  Max recharge limit (cfs) - see iwell in control file.");
                @out.println(cmnt);
                @out.println(cmnt + "   ID                Name          DownStream     Comment    GWMax  ");
                @out.println(cmnt + "---------eb----------------------eb----------exb----------exb------e");
                if (doWell)
                {
                    format = "%-12.12s%-24.24s%-12.12s %-12.12s %8.8s";
                }
                else
                {
                    format = "%-12.12s%-24.24s%-12.12s %-12.12s";
                }
                @out.println(cmnt);
                @out.println(cmnt + "EndHeader");
                @out.println(cmnt);

                int num = 0;
                if (theRivs != null)
                {
                    num = theRivs.Count;
                }
                IList <object> v = new List <object>(5);
                for (int i = 0; i < num; i++)
                {
                    riv = theRivs[i];
                    v.Clear();
                    v.Add(riv.getID());
                    v.Add(riv.getName());
                    v.Add(riv.getCstadn());
                    v.Add(riv.getComment());
                    if (doWell)
                    {
                        // Format as string since main format uses string.
                        v.Add(StringUtil.formatString(riv.getGwmaxr(), "%8.0f"));
                    }
                    iline = StringUtil.formatString(v, format);
                    @out.println(iline);
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
コード例 #29
0
        /// <summary>
        /// Write the new (updated) delay table file.  This routine writes the new delay
        /// table file.  If an original file is specified, then the original header is
        /// carried into the new file.  The writing of data is done by the dumpDelayFile
        /// routine which now does not mess with headers. </summary>
        /// <param name="inputFile"> old file (used as input) </param>
        /// <param name="outputFile"> new file to create </param>
        /// <param name="dly"> list of delays </param>
        /// <param name="newcomments"> new comments to save with the header of the file </param>
        /// <exception cref="Exception"> if an error occurs </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeStateCUFile(String inputFile, String outputFile, java.util.List<DWR.StateMod.StateMod_DelayTable> dly, java.util.List<String> newcomments) throws Exception
        public static void writeStateCUFile(string inputFile, string outputFile, IList <StateMod_DelayTable> dly, IList <string> newcomments)
        {
            PrintWriter    @out       = null;
            IList <string> commentStr = new List <string>(1);

            commentStr.Add("#");
            IList <string> ignoreCommentStr = new List <string>(1);

            ignoreCommentStr.Add("#>");
            string routine = "StateMod_DelayTable.writeStateCUFile";

            Message.printStatus(2, routine, "Writing new delay table to file \"" + outputFile + "\" using \"" + inputFile + "\" header...");

            try
            {
                // Process the header from the old file...
                @out = IOUtil.processFileHeaders(IOUtil.getPathUsingWorkingDir(inputFile), IOUtil.getPathUsingWorkingDir(outputFile), newcomments, commentStr, ignoreCommentStr, 0);

                // Now write the new data...
                string cmnt               = "#>";
                string m_format           = "%8.2f";
                StateMod_DelayTable delay = null;

                @out.println(cmnt);
                @out.println(cmnt + " *******************************************************");
                @out.println(cmnt + " StateCU Delay (Return flow) Table");
                @out.println(cmnt);
                @out.println(cmnt + "     Format (a8, i4, (12f8.2)");
                @out.println(cmnt);
                @out.println(cmnt + "   ID       idly: Delay table id");
                @out.println(cmnt + "   Ndly     ndly: Number of entries in delay table idly.");
                @out.println(cmnt + "   Ret  dlyrat(1-n,idl): Return for month n, station idl");
                @out.println(cmnt);
                @out.println(cmnt + " ID   Ndly  Ret1    Ret2    Ret3    Ret4    Ret5    Ret6  " + "  Ret7    Ret8    Ret9    Ret10   Ret11   Ret12...");
                @out.println(cmnt + "-----eb--eb------eb------eb------eb------eb------eb------e" + "b------eb------eb------eb------eb------eb------e...");
                @out.println(cmnt + "EndHeader");
                @out.println(cmnt);

                int ndly = 0;
                if (dly != null)
                {
                    ndly = dly.Count;
                }
                if (Message.isDebugOn)
                {
                    Message.printDebug(3, routine, "Printing " + ndly + " delay table entries.");
                }

                StringBuilder b     = new StringBuilder();
                int           j     = 0; // Index for returns in a table
                int           nvals = 0; // Number of returns in a table
                bool          printed;   // Indicates if a line of output was printed, to help handle 12 values or less per line
                for (int i = 0; i < ndly; i++)
                {
                    delay    = dly[i];
                    b.Length = 0;
                    b.Append(StringUtil.formatString(delay.getTableID(), "%8d"));
                    b.Append(StringUtil.formatString(delay.getNdly(), "%4d"));
                    nvals   = delay.getNdly();
                    printed = false;
                    for (j = 0; j < nvals; j++)
                    {
                        b.Append(StringUtil.formatString(delay.getRet_val(j), m_format));
                        printed = false;
                        if (((j + 1) % 12) == 0)
                        {
                            // Print the output and initialize a new line...
                            @out.println(b.ToString());
                            b.Length = 0;
                            b.Append("            ");
                            printed = true;
                        }
                    }
                    if (!printed)
                    {
                        // Print the last line of output...
                        @out.println(b.ToString());
                    }
                }
            }
            catch (Exception e)
            {
                Message.printWarning(2, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.close();
                }
            }
        }
コード例 #30
0
        /// <summary>
        /// Writes a list of StateCU_BlaneyCriddle objects to a list file.  A header is
        /// printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the Vector of objects to write. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateCU_BlaneyCriddle> data, java.util.List<String> outputComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_BlaneyCriddle> data, IList <string> outputComments)
        {
            string routine = "StateCU_BlaneyCriddle.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("Name");
            fields.Add("CurveType");
            fields.Add("DayPercent");
            fields.Add("Coefficient");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_BLANEY_CRIDDLE;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = (string)fields[i];
                names[i]   = StateCU_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateCU_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int                   j             = 0;
            int                   k             = 0;
            PrintWriter           @out          = null;
            StateCU_BlaneyCriddle bc            = null;
            IList <string>        commentString = new List <string>(1);

            commentString.Add("#");
            IList <string> ignoreCommentString = new List <string>(1);

            ignoreCommentString.Add("#>");
            string[]      line   = new string[fieldCount];
            string        flag   = null;
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  However, do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (outputComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(outputComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateCU Blaney-Criddle crop coefficients as a delimited list file.");
                newComments2.Insert(2, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentString, ignoreCommentString, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    bc   = (StateCU_BlaneyCriddle)data[i];
                    flag = bc.getFlag();
                    if (flag.Equals("Percent", StringComparison.OrdinalIgnoreCase))
                    {
                        for (j = 0; j < 21; j++)
                        {
                            line[0] = StringUtil.formatString(bc.getName(), formats[0]).Trim();
                            line[1] = StringUtil.formatString(bc.getFlag(), formats[1]).Trim();
                            line[2] = StringUtil.formatString(bc.getNckca(j), formats[2]).Trim();
                            line[3] = StringUtil.formatString(bc.getCkca(j), formats[3]).Trim();

                            buffer = new StringBuilder();
                            for (k = 0; k < fieldCount; k++)
                            {
                                if (k > 0)
                                {
                                    buffer.Append(delimiter);
                                }
                                if (line[k].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                                {
                                    line[k] = "\"" + line[k] + "\"";
                                }
                                buffer.Append(line[k]);
                            }
                            @out.println(buffer.ToString());
                        }
                    }
                    else
                    {
                        for (j = 0; j < 25; j++)
                        {
                            line[0] = StringUtil.formatString(bc.getName(), formats[0]).Trim();
                            line[1] = StringUtil.formatString(bc.getFlag(), formats[1]).Trim();
                            line[2] = StringUtil.formatString(bc.getNckcp(j), formats[2]).Trim();
                            line[3] = StringUtil.formatString(bc.getCkcp(j), formats[3]).Trim();

                            buffer = new StringBuilder();
                            for (k = 0; k < fieldCount; k++)
                            {
                                if (k > 0)
                                {
                                    buffer.Append(delimiter);
                                }
                                if (line[k].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                                {
                                    line[k] = "\"" + line[k] + "\"";
                                }
                                buffer.Append(line[k]);
                            }
                            @out.println(buffer.ToString());
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
                @out = null;
            }
        }
コード例 #31
0
        /// <summary>
        /// Writes a list of StateMod_ReservoirAreaCap objects to a list file.  A header
        /// is printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the list of objects to write. </param>
        /// <param name="newComments"> new comments to add at the top of the file. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List<StateMod_ReservoirAreaCap> data, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_ReservoirAreaCap> data, IList <string> newComments)
        {
            string routine = "StateMod_ReservoirAreaCap.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            IList <string> fields = new List <string>();

            fields.Add("ReservoirID");
            fields.Add("Content");
            fields.Add("Area");
            fields.Add("Seepage");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateMod_Util.COMP_RESERVOIR_AREA_CAP;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = (string)fields[i];
                names[i]   = StateMod_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int         j    = 0;
            PrintWriter @out = null;
            StateMod_ReservoirAreaCap area = null;

            string[]       line = new string[fieldCount];
            IList <string> commentIndicators = new List <string>(1);

            commentIndicators.Add("#");
            IList <string> ignoredCommentIndicators = new List <string>(1);

            ignoredCommentIndicators.Add("#>");
            StringBuilder buffer = new StringBuilder();

            try
            {
                // Add some basic comments at the top of the file.  Do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                IList <string> newComments2 = null;
                if (newComments == null)
                {
                    newComments2 = new List <string>();
                }
                else
                {
                    newComments2 = new List <string>(newComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateMod reservoir content/area/seepage data as a delimited list file.");
                newComments2.Insert(2, "See also the associated station, account, precipitation station,");
                newComments2.Insert(3, "evaporation station, and collection files.");
                newComments2.Insert(4, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    if (i > 0)
                    {
                        buffer.Append(delimiter);
                    }
                    buffer.Append("\"" + names[i] + "\"");
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    area = (StateMod_ReservoirAreaCap)data[i];

                    line[0] = StringUtil.formatString(area.getCgoto(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(area.getConten(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(area.getSurarea(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(area.getSeepage(), formats[3]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (j > 0)
                        {
                            buffer.Append(delimiter);
                        }
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                    }

                    @out.println(buffer.ToString());
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
コード例 #32
0
        /// <summary>
        /// Writes a list of StateMod_ReservoirAccount objects to a list file.  A header
        /// is printed to the top of the file, containing the commands used to generate the
        /// file.  Any strings in the body of the file that contain the field delimiter will be wrapped in "...". </summary>
        /// <param name="filename"> the name of the file to which the data will be written. </param>
        /// <param name="delimiter"> the delimiter to use for separating field values. </param>
        /// <param name="update"> whether to update an existing file, retaining the current
        /// header (true) or to create a new file with a new header. </param>
        /// <param name="data"> the list of objects to write. </param>
        /// <param name="newComments"> new comments to add to the top of the file. </param>
        /// <exception cref="Exception"> if an error occurs. </exception>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public static void writeListFile(String filename, String delimiter, boolean update, java.util.List data, java.util.List newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, System.Collections.IList data, System.Collections.IList newComments)
        {
            string routine = "StateMod_ReservoirAccount.writeListFile";
            int    size    = 0;

            if (data != null)
            {
                size = data.Count;
            }

            System.Collections.IList fields = new List <object>();
            fields.Add("ReservoirID");
            fields.Add("OwnerID");
            fields.Add("OwnerAccount");
            fields.Add("MaxStorage");
            fields.Add("InitialStorage");
            fields.Add("ProrateEvap");
            fields.Add("OwnershipTie");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateMod_DataSet.COMP_RESERVOIR_STATION_ACCOUNTS;
            string   s       = null;

            for (int i = 0; i < fieldCount; i++)
            {
                s          = (string)fields[i];
                names[i]   = StateMod_Util.lookupPropValue(comp, "FieldName", s);
                formats[i] = StateMod_Util.lookupPropValue(comp, "Format", s);
            }

            string oldFile = null;

            if (update)
            {
                oldFile = IOUtil.getPathUsingWorkingDir(filename);
            }

            int j = 0;
            StateMod_ReservoirAccount acct = null;

            System.Collections.IList commentIndicators = new List <object>(1);
            commentIndicators.Add("#");
            System.Collections.IList ignoredCommentIndicators = new List <object>(1);
            ignoredCommentIndicators.Add("#>");
            string[]      line   = new string[fieldCount];
            StringBuilder buffer = new StringBuilder();
            PrintWriter   @out   = null;

            try
            {
                // Add some basic comments at the top of the file.  Do this to a copy of the
                // incoming comments so that they are not modified in the calling code.
                System.Collections.IList newComments2 = null;
                if (newComments == null)
                {
                    newComments2 = new List <object>();
                }
                else
                {
                    newComments2 = new List <object>(newComments);
                }
                newComments2.Insert(0, "");
                newComments2.Insert(1, "StateMod reservoir station accounts as a delimited list file.");
                newComments2.Insert(2, "See also the associated station, precipitation station, evaporation station,");
                newComments2.Insert(3, "content/area/seepage, and collection files.");
                newComments2.Insert(4, "");
                @out = IOUtil.processFileHeaders(oldFile, IOUtil.getPathUsingWorkingDir(filename), newComments2, commentIndicators, ignoredCommentIndicators, 0);

                for (int i = 0; i < fieldCount; i++)
                {
                    buffer.Append("\"" + names[i] + "\"");
                    if (i < (fieldCount - 1))
                    {
                        buffer.Append(delimiter);
                    }
                }

                @out.println(buffer.ToString());

                for (int i = 0; i < size; i++)
                {
                    acct = (StateMod_ReservoirAccount)data[i];

                    line[0] = StringUtil.formatString(acct.getCgoto(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(acct.getID(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(acct.getName(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(acct.getOwnmax(), formats[3]).Trim();
                    line[4] = StringUtil.formatString(acct.getCurown(), formats[4]).Trim();
                    line[5] = StringUtil.formatString(acct.getPcteva(), formats[5]).Trim();
                    line[6] = StringUtil.formatString(acct.getN2own(), formats[6]).Trim();

                    buffer = new StringBuilder();
                    for (j = 0; j < fieldCount; j++)
                    {
                        if (line[j].IndexOf(delimiter, StringComparison.Ordinal) > -1)
                        {
                            line[j] = "\"" + line[j] + "\"";
                        }
                        buffer.Append(line[j]);
                        if (j < (fieldCount - 1))
                        {
                            buffer.Append(delimiter);
                        }
                    }

                    @out.println(buffer.ToString());
                }
            }
            catch (Exception e)
            {
                Message.printWarning(3, routine, e);
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }