~ubuntu-branches/ubuntu/jaunty/electric/jaunty

« back to all changes in this revision

Viewing changes to com/sun/electric/tool/io/output/Output.java

  • Committer: Bazaar Package Importer
  • Author(s): Onkar Shinde
  • Date: 2009-01-08 02:05:08 UTC
  • mfrom: (1.1.2 upstream) (3.1.4 sid)
  • Revision ID: james.westby@ubuntu.com-20090108020508-0h3li7zt9mu5gf0i
Tags: 8.08-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
62
62
import java.io.FileWriter;
63
63
import java.io.IOException;
64
64
import java.io.PrintWriter;
 
65
import java.io.StringWriter;
65
66
import java.net.URL;
66
67
import java.text.SimpleDateFormat;
 
68
import java.util.ArrayList;
67
69
import java.util.Comparator;
68
70
import java.util.Date;
69
71
import java.util.HashMap;
113
115
 
114
116
        /** file path */                                                                        protected String filePath;
115
117
        /** for writing text files */                                           protected PrintWriter printWriter;
 
118
        /** for writing text arrays */                                          protected StringWriter stringWriter;
116
119
        /** for writing binary files */                                         protected DataOutputStream dataOutputStream;
117
120
        /** True to write with less information displayed */protected boolean quiet;
118
121
 
536
539
    }
537
540
 
538
541
    /**
539
 
     * Opens the dataOutputStream for writing of binary files.
 
542
     * Opens output for writing binary files.
 
543
     * @param filePath the name of the file.
540
544
     * @return true on error.
541
545
     */
542
546
    protected boolean openBinaryOutputStream(String filePath)
558
562
    }
559
563
 
560
564
    /**
561
 
     * Closes the dataOutputStream.
 
565
     * Close output for writing binary to a file.
562
566
     * @return true on error.
563
567
     */
564
568
    protected boolean closeBinaryOutputStream()
575
579
    }
576
580
 
577
581
    /**
578
 
     * Open the printWriter for writing text files
 
582
     * Open output for writing text to a file.
 
583
     * @param filePath the name of the file.
579
584
     * @return true on error.
580
585
     */
581
586
    protected boolean openTextOutputStream(String filePath)
593
598
    }
594
599
 
595
600
        /**
596
 
     * Close the printWriter.
 
601
     * Close output for writing text to a file.
597
602
     * @return true on error.
598
603
     */
599
604
    protected boolean closeTextOutputStream()
602
607
        return false;
603
608
    }
604
609
 
 
610
    /**
 
611
     * Open output for collecting a list of strings.
 
612
     */
 
613
    protected void openStringsOutputStream()
 
614
    {
 
615
        stringWriter = new StringWriter();
 
616
    }
 
617
 
 
618
        /**
 
619
     * Close output for collecting a list of strings.
 
620
     * @return the list of strings.
 
621
     */
 
622
    protected List<String> closeStringsOutputStream()
 
623
    {
 
624
        StringBuffer sb = stringWriter.getBuffer();
 
625
        String [] lines = sb.toString().split("\n");
 
626
        List<String> strings = new ArrayList<String>();
 
627
        for(int i=0; i<lines.length; i++)
 
628
                strings.add(lines[i]);
 
629
        return strings;
 
630
    }
 
631
 
 
632
    /**
 
633
     * Method to write copyright header information to the output.
 
634
     * @param prefix the characters that start a line of commented output.
 
635
     * @param postfix the characters that end a line of commented output.
 
636
     */
605
637
        protected void emitCopyright(String prefix, String postfix)
606
638
        {
607
639
                if (!IOTool.isUseCopyrightMessage()) return;
612
644
                        int endPos = str.indexOf('\n', start);
613
645
                        if (endPos < 0) endPos = str.length();
614
646
                        String oneLine = str.substring(start, endPos);
615
 
                        printWriter.println(prefix + oneLine + postfix);
 
647
                        writeChunk(prefix + oneLine + postfix + "\n");
616
648
                        start = endPos+1;
617
649
                }
618
650
        }
622
654
        private boolean strictWidthLimit = false;
623
655
        private String continuationString = "";
624
656
 
 
657
        /**
 
658
         * Method to set the size of a line of output.
 
659
         * @param width the maximum number of characters on a line of output (default is 80).
 
660
         * @param strict true to strictly enforce the line-width limit, even if it means breaking
 
661
         * a symbol in the middle.  When false, very long names may exceed the width limit.
 
662
         */
625
663
        protected void setOutputWidth(int width, boolean strict) { maxWidth = width;   strictWidthLimit = strict; }
626
664
 
 
665
        /**
 
666
         * Method to set the string that will be emitted at the start of a "continuation line".
 
667
         * The continuation line is the line that follows a line which is broken up because
 
668
         * of width limits.
 
669
         * @param str the string that will be emitted at the start of a "continuation line".
 
670
         */
627
671
        protected void setContinuationString(String str) { continuationString = str; }
628
672
 
629
673
        private void writeChunk(String str)
630
674
        {
631
675
                int len = str.length();
632
676
                if (len <= 0) return;
633
 
                printWriter.print(str);
 
677
                if (printWriter != null) printWriter.print(str); else
 
678
                        if (stringWriter != null) stringWriter.write(str);
634
679
                lineCharCount += len;
635
680
                if (str.charAt(len-1) == '\n') lineCharCount = 0;
636
681
        }
637
682
 
638
683
        /**
639
 
         * Write to the file, but break into printable lines
 
684
         * Method to add a string to the output, limited by the maximum
 
685
         * width of an output line.
 
686
         * @param str the string to add to the output.
640
687
         */
641
688
        protected void writeWidthLimited(String str)
642
689
        {