/// <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();
                }
            }
        }
Пример #2
0
        private void Write(RotatingFileOutputStreamSupplier supplier, string line)
        {
            PrintWriter writer = new PrintWriter(supplier.Get());

            writer.println(line);
            writer.flush();
        }
Пример #3
0
 private void MaybeFlush(PrintWriter writer)
 {
     if (_autoFlush)
     {
         writer.flush();
     }
 }
Пример #4
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);
            }
        }
Пример #5
0
        private string PrintToStream(Result result)
        {
            StringWriter stringWriter = new StringWriter();
            PrintWriter  printWriter  = new PrintWriter(stringWriter);

            result.WriteAsStringTo(printWriter);
            printWriter.flush();
            return(stringWriter.ToString());
        }
Пример #6
0
 internal virtual void WriteValues(Locale locale, long timestamp, string line, object[] values)
 {
     lock (this)
     {
         StreamSupplier.get();
         PrintWriter.printf(locale, string.format(locale, "%d,%s%n", timestamp, line), values);
         PrintWriter.flush();
     }
 }
Пример #7
0
 public virtual void PrintAllCauses(PrintWriter writer)
 {
     if (Cause == null)
     {
         foreach (Entry entry in _causes)
         {
             entry.Failure.printStackTrace(writer);
         }
         writer.flush();
     }
 }
Пример #8
0
 /// <summary>
 /// Flushes servers stream
 /// </summary>
 public override void flush()
 {
     if (_outputMode == OutputMode.CharWriter)
     {
         _printWriter.flush();
     }
     else
     {
         _outputStream.flush();
     }
 }
        /// <summary>
        /// Outputs the report as an ASCII table.
        /// </summary>
        /// <param name="report">  the report </param>
        /// <param name="out">  the output stream to write to </param>
        public virtual void writeAsciiTable(R report, Stream @out)
        {
            IList <Type> columnTypes = getColumnTypes(report);
            IList <AsciiTableAlignment> alignments = IntStream.range(0, columnTypes.Count).mapToObj(i => calculateAlignment(columnTypes[i])).collect(toImmutableList());
            IList <string> headers = report.ColumnHeaders;
            ImmutableList <ImmutableList <string> > cells = formatAsciiTable(report);
            string      asciiTable = AsciiTable.generate(headers, alignments, cells);
            PrintWriter pw         = new PrintWriter(new StreamWriter(@out, Encoding.UTF8));

            pw.println(asciiTable);
            pw.flush();
        }
Пример #10
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void processFileUpload(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException
        private void processFileUpload(HttpServletRequest req, HttpServletResponse resp)
        {
            System.IO.Stream @is  = req.InputStream;
            PrintWriter      @out = resp.Writer;

            resp.ContentType = "text/plain";
            string fileContents = getContent(@is);

            @out.print(fileContents.Trim());
            @out.flush();
            resp.Status = HttpServletResponse.SC_OK;
        }
Пример #11
0
            public virtual void PrintStackTrace(StringBuilder sb)
            {
                StringWriter w  = new StringWriter();
                PrintWriter  pw = new PrintWriter(w);

                if (Trace != null)
                {
                    Trace.printStackTrace(pw);
                }
                pw.flush();
                sb.Append(w);
                sb.Append('\n');
            }
Пример #12
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);
        }
Пример #13
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void handle(String target, org.eclipse.jetty.server.Request baseRequest, javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response) throws java.io.IOException
            public override void handle(string target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
            {
                response.ContentType = "text/plain; charset=utf-8";
                response.Status      = HttpServletResponse.SC_OK;
                PrintWriter @out = response.Writer;

                writeBatch(@out, _firstBatchSize);
                @out.flush();
                _latch.start();
                _innerBarrier.reached();

                _latch.finish();
                writeBatch(@out, _otherBatchSize);
                baseRequest.Handled = true;
            }
Пример #14
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void processMultiPart(javax.servlet.http.HttpServletRequest req, javax.servlet.http.HttpServletResponse resp) throws java.io.IOException
        private void processMultiPart(HttpServletRequest req, HttpServletResponse resp)
        {
            PrintWriter @out = resp.Writer;

            resp.ContentType = "text/plain";
            MultipartParser mp   = new MultipartParser(req, 2048);
            Part            part = null;

            while ((part = mp.readNextPart()) != null)
            {
                string name = part.Name.Trim();
                if (part.Param)
                {
                    // it's a parameter part
                    ParamPart paramPart = (ParamPart)part;
                    string    value     = paramPart.StringValue.Trim();
                    LOG.info("param; name=" + name + ", value=" + value);
                    @out.print("param; name=" + name + ", value=" + value);
                }
                else if (part.File)
                {
                    // it's a file part
                    FilePart filePart = (FilePart)part;
                    string   fileName = filePart.FileName;
                    if (!string.ReferenceEquals(fileName, null))
                    {
                        // the part actually contained a file
                        // StringWriter sw = new StringWriter();
                        // long size = filePart.writeTo(new File(System
                        // .getProperty("java.io.tmpdir")));
                        System.IO.MemoryStream baos = new System.IO.MemoryStream();
                        long size = filePart.writeTo(baos);
                        LOG.info("file; name=" + name + "; filename=" + fileName + ", filePath=" + filePart.FilePath + ", content type=" + filePart.ContentType + ", size=" + size);
                        @out.print(string.Format("{0}: {1}", name, (StringHelperClass.NewString(baos.toByteArray())).Trim()));
                    }
                    else
                    {
                        // the field did not contain a file
                        LOG.info("file; name=" + name + "; EMPTY");
                    }
                    @out.flush();
                }
            }
            resp.Status = HttpServletResponse.SC_OK;
        }
Пример #15
0
        protected internal virtual void dump(PrintWriter @out)
        {
            Iterator iterator = this.nodes.values().iterator();

            while (iterator.hasNext())
            {
                Node node = (Node)iterator.next();
                node.dump(@out);
            }
            iterator = this.edges.iterator();
            while (iterator.hasNext())
            {
                Edge edge = (Edge)iterator.next();
                edge.dump(@out);
            }
            @out.println(new StringBuilder().append("initialNode: ").append(this.initialNode.getId()).toString());
            @out.println(new StringBuilder().append("terminalNode: ").append(this.terminalNode.getId()).toString());
            @out.println(new StringBuilder().append("logBase: ").append(this.logMath.getLogBase()).toString());
            @out.flush();
        }
Пример #16
0
        public RecordSetMD mReadMapFor(JniPMMLItem aJniPMMLItem, PrintWriter pw, Boolean bFillDictionaryNames)
        //throws com.WDataSci.WDS.WDSException
        {
            try {
                if (!this.Mode.bIn(RecordSetMDEnums.eMode.Input, RecordSetMDEnums.eMode.Internal))
                {
                    throw new WDSException("Error, wrong mode for RecordSetMD.mReadMapFor(JniPMML)!");
                }

                if (this.SchemaType.equals(RecordSetMDEnums.eSchemaType.XSD))
                {
                    this.SchemaMatter.mReadMapFor(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }
                else if (this.SchemaType.equals(RecordSetMDEnums.eSchemaType.NamingConvention) && this.Type.isFlatFile())
                {
                    this.FileMatter.mReadMapFor(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }
                else if (this.Type.equals(RecordSetMDEnums.eType.HDF5))
                {
                    this.HDF5Matter.mReadMapFor(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }
                else if (this.Type.equals(RecordSetMDEnums.eType.DBB))
                {
                    this.DBBMatter.mReadMap(this, aJniPMMLItem, pw, bFillDictionaryNames);
                }

                if (pw != null)
                {
                    pw.printf("leaving RecordSetMD.mReadMapFor constructor\n");
                }
                if (pw != null)
                {
                    pw.flush();
                }
                return(this);
            }
            catch (Exception e) {
                throw new WDSException("Error in RecordSetMD.mReadMapFor", e);
            }
        }
Пример #17
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;
        }
Пример #18
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void export(org.neo4j.graphdb.GraphDatabaseService db) throws java.io.IOException
        public virtual void Export(GraphDatabaseService db)
        {
            FileStream  stream = new FileStream(_target, FileMode.Create, FileAccess.Write);
            PrintWriter @out   = new PrintWriter(stream);

            @out.println("digraph G {");
            @out.println("    rankdir=LR;");

            using (Transaction tx = Db.beginTx())
            {
                ISet <Node>       seen      = new HashSet <Node>();
                LinkedList <Node> toExplore = new LinkedList <Node>();
                toExplore.AddLast(Db.getNodeById(0));

                while (toExplore.Count > 0)
                {
                    Node current = toExplore.RemoveFirst();

                    @out.println("    " + current.Id + " [shape=box,label=\"" + current.GetProperty("description") + "\"];");
                    foreach (Relationship relationship in current.Relationships)
                    {
                        @out.println("    " + current.Id + " -> " + relationship.EndNode.Id + " [label=\"" + relationship.GetProperty("description") + "\"];");

                        if (!seen.Contains(relationship.EndNode))
                        {
                            toExplore.AddLast(relationship.EndNode);
                            seen.Add(relationship.EndNode);
                        }
                    }
                }

                tx.Success();
            }

            @out.println("}");

            @out.flush();
            stream.Close();
        }
Пример #19
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);
     }
 }
Пример #20
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();
                }
            }
        }
Пример #21
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;
            }
        }
Пример #22
0
        public void mReadMap(RecordSetMD aRecordSetMD, JniPMMLItem aJniPMML, PrintWriter pw, Boolean bFillDictionaryNames)
        //throws com.WDataSci.WDS.WDSException
        {
            try {
                int i  = -1;
                int ii = -1;
                int j  = -1;
                int jj = -1;
                int k  = -1;
                int kk = -1;


                //Java Boolean bUsingPMML = (aJniPMML != null && aJniPMML.PMMLMatter.Doc != null);
                //C#
                Boolean bUsingPMML = false;

                String[] lFieldStringNames = null;
                int      nDataFieldNames   = 0;
                if (bUsingPMML)
                {
                    lFieldStringNames = aJniPMML.PMMLDataFieldStringNames();
                    nDataFieldNames   = lFieldStringNames.Length;
                }

                if (pw != null)
                {
                    pw.printf("In RecordSetMD constructor\n");
                }
                if (pw != null)
                {
                    pw.flush();
                }

                //point to file or memory
                DBB buffer = this.Header.Buffer;
                buffer.position(0, 0, 0);

                try {
                    //get compound dataset information

                    long nColumns = buffer.nRecords;
                    long nBlockMaxStringByteLength = this.Header.MaxStringByteLength;

                    int nBlockCoreColumnSize = (int)(buffer.nRecordFLenBytes);
                    int nBlockAllocatedSize  = (int)(buffer.nDBBRequiredBytes);

                    if (nBlockAllocatedSize > this.Header.Buffer.Length)
                    {
                        throw new com.WDataSci.WDS.WDSException("Error, HeaderBuffer capacity, " + this.Header.Buffer.Length
                                                                + ", is less then what should be BlockAllocatedSize, " + nBlockAllocatedSize
                                                                );
                    }

                    int nBlockCoreSize = (int)(buffer.nDBBLeadingBytes + buffer.nDBBFLenBytes);

                    if (pw != null)
                    {
                        pw.printf("In RecordSetMD constructor, nColumns=%d\n", nColumns);
                    }
                    if (pw != null)
                    {
                        pw.flush();
                    }

                    byte[] namebuffer = new byte[(int)(nBlockMaxStringByteLength)];


                    //iterate through columns (dataset members)

                    aRecordSetMD.Column = new FieldMD[(int)(nColumns)];

                    int bptr = 0;

                    for (ii = 0; ii < nColumns; ii++, bptr += (int)nBlockCoreColumnSize)
                    {
                        buffer.position(buffer.ptr, bptr, buffer.vlenptr);

                        aRecordSetMD.Column[ii] = new FieldMD();
                        FieldMD col = aRecordSetMD.Column[ii];

                        //the first two fields are always names and taken to be variable length
                        col.Name = buffer.GetLayerVLenString(1, nBlockMaxStringByteLength);

                        //Check for PMML DataFieldName map
                        //If not mapped externally, the next VLenString pointer will be 0 and will come back as empty
                        String tmpname = buffer.GetLayerVLenString(1, nBlockMaxStringByteLength);

                        //Search for PMML DataFieldName map, take input supplied map first, then the usual search

                        /* Java >>> *
                         * Boolean found = false;
                         * if ( bUsingPMML && tmpname.length() > 0 ) {
                         *  for (j = 0; !found && j < nDataFieldNames; j++) {
                         *      if ( tmpname.equals(lFieldStringNames[j]) ) {
                         *          col.MapToMapKey(lFieldStringNames[j]);
                         *          found = true;
                         *          break;
                         *      }
                         *  }
                         * }
                         * if ( bUsingPMML && !found ) {
                         *  for (j = 0; !found && j < nDataFieldNames; j++) {
                         *      if ( col.Name.equals(lFieldStringNames[j]) ) {
                         *          col.MapToMapKey(lFieldNames[j]);
                         *          found = true;
                         *          break;
                         *      }
                         *  }
                         * }
                         * /* <<< Java */
                        if (!bUsingPMML && bFillDictionaryNames)
                        {
                            col.MapToMapKey(col.Name);
                        }

                        //Java col.DTyp = FieldMDEnums.eDTyp.FromInt(buffer.GetLayerInt(1));
                        //C#
                        col.DTyp = FieldMDExt.eDTyp_FromInt((int)buffer.GetLayerInt(1));

                        //See notes above on Date and DateTime types
                        //Since the header block is being passed in, Date and DateTime types are provided.

                        col.ByteMemLength = (long)buffer.GetLayerLong(1);
                        col.ByteMaxLength = (long)buffer.GetLayerLong(1);
                        if (col.DTyp.bIn(FieldMDEnums.eDTyp.VLS, FieldMDEnums.eDTyp.Str))
                        {
                            col.StringMaxLength = (int)(col.ByteMaxLength / 2);
                        }

                        //no longer using the last byte for bIsMappedToPMMLFieldName, so there is filler space at the end
                    }
                }
                catch (Exception e) {
                    throw new com.WDataSci.WDS.WDSException("Error in RecordSetMD processing of Header DBB:", e);
                }

                if (pw != null)
                {
                    pw.printf("leaving RecordSetMD constructor\n");
                }
                if (pw != null)
                {
                    pw.flush();
                }
            }
            catch (Exception e) {
                throw new com.WDataSci.WDS.WDSException("Error in ProcessInputMapFor", e);
            }
        }
Пример #23
0
 public virtual void Println(string value)
 {
     @out.println(value);
     @out.flush();
 }
Пример #24
0
        /// <summary>
        /// Writes a list of StateCU_PenmanMonteith 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>
        /// <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_PenmanMonteith> data, java.util.List<String> outputComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateCU_PenmanMonteith> data, IList <string> outputComments)
        {
            string routine = "StateCU_PenmanMonteith.writeListFile";
            int    size    = 0;

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

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

            fields.Add("Name");
            fields.Add("GrowthStage");
            fields.Add("Percent");
            fields.Add("Coefficient");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateCU_DataSet.COMP_PENMAN_MONTEITH;
            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;
            int            k             = 0;
            PrintWriter    @out          = 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 Penman-Monteith 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());
                StateCU_PenmanMonteith kpm;
                for (int i = 0; i < size; i++)
                {
                    kpm = data[i];
                    int ngs   = kpm.getNGrowthStages();
                    int ncpgs = StateCU_PenmanMonteith.getNCoefficientsPerGrowthStage();
                    for (int igs = 0; igs < ngs; igs++)
                    {
                        for (j = 0; j < ncpgs; j++)
                        {
                            line[0] = StringUtil.formatString(kpm.getName(), formats[0]).Trim();
                            line[1] = StringUtil.formatString((igs + 1), formats[1]).Trim();
                            line[2] = StringUtil.formatString(kpm.getKcday(igs, j), formats[2]).Trim();
                            line[3] = StringUtil.formatString(kpm.getKcb(igs, 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;
            }
        }
        /// <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();
                }
            }
        }
        /// <summary>
        /// Writes a list of StateMod_StreamGage 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"> list of 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_StreamGage> data, java.util.List<String> newComments) throws Exception
        public static void writeListFile(string filename, string delimiter, bool update, IList <StateMod_StreamGage> data, IList <string> newComments)
        {
            int size = 0;

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

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

            fields.Add("ID");
            fields.Add("Name");
            fields.Add("NodeID");
            fields.Add("DailyID");
            int fieldCount = fields.Count;

            string[] names   = new string[fieldCount];
            string[] formats = new string[fieldCount];
            int      comp    = StateMod_DataSet.COMP_STREAMGAGE_STATIONS;
            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_StreamGage gage = null;
            IList <string>      commentIndicators = new List <string>(1);

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

            ignoredCommentIndicators.Add("#>");
            string[]      line   = new string[fieldCount];
            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 stream gage stations as a delimited list file.");
                newComments2.Insert(2, "");
                @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++)
                {
                    gage = (StateMod_StreamGage)data[i];

                    line[0] = StringUtil.formatString(gage.getID(), formats[0]).Trim();
                    line[1] = StringUtil.formatString(gage.getName(), formats[1]).Trim();
                    line[2] = StringUtil.formatString(gage.getCgoto(), formats[2]).Trim();
                    line[3] = StringUtil.formatString(gage.getCrunidy(), 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)
            {
                throw e;
            }
            finally
            {
                if (@out != null)
                {
                    @out.flush();
                    @out.close();
                }
            }
        }
        /// <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();
                }
            }
        }
        /// <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();
                }
            }
        }
        /// <summary>
        /// Write the new (updated) stream gage stations 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_StreamGage to write. </param>
        /// <param name="newcomments"> New comments to write in the file header. </param>
        /// <param name="do_daily"> Indicates whether daily 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_StreamGage> theRivs, java.util.List<String> newcomments, boolean do_daily) throws Exception
        public static void writeStateModFile(string infile, string outfile, IList <StateMod_StreamGage> theRivs, IList <string> newcomments, bool do_daily)
        {
            PrintWriter    @out = null;
            IList <string> commentIndicators = new List <string>(1);

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

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

            if (Message.isDebugOn)
            {
                Message.printDebug(2, routine, "Writing stream gage stations to 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_StreamGage riv = null;

                @out.println(cmnt + " *******************************************************");
                @out.println(cmnt + "  Stream Gage Station File");
                @out.println(cmnt);
                @out.println(cmnt + "     format:  (a12, a24, a12, 1x, a12)");
                @out.println(cmnt);
                @out.println(cmnt + "  ID         crunid:  Station ID");
                @out.println(cmnt + "  Name       runnam:  Station name");
                @out.println(cmnt + "  River ID    cgoto:  River node with stream gage");
                @out.println(cmnt + "  Daily ID  crunidy:  Daily stream station ID.");
                @out.println(cmnt);
                @out.println(cmnt + "    ID              Name           River ID     Daily ID   ");
                @out.println(cmnt + "---------eb----------------------eb----------exb----------e");
                if (do_daily)
                {
                    format = "%-12.12s%-24.24s%-12.12s %-12.12s";
                }
                else
                {
                    format = "%-12.12s%-24.24s%-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.getCgoto());
                    if (do_daily)
                    {
                        v.Add(riv.getCrunidy());
                    }
                    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();
                }
            }
        }
        /// <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();
                }
            }
        }