1 19 20 package org.netbeans.lib.cvsclient.command.annotate; 21 22 import java.io.*; 23 import java.util.*; 24 25 import org.netbeans.lib.cvsclient.command.*; 26 27 33 public class AnnotateInformation extends FileInfoContainer { 34 37 private File file; 38 39 42 private List linesList; 43 44 private Iterator iterator; 45 46 private File tempFile; 47 48 private File tempDir; 49 50 private BufferedOutputStream tempOutStream; 51 52 public AnnotateInformation() { 53 this.tempDir = null; 54 } 55 56 public AnnotateInformation(File tempDir) { 57 this.tempDir = tempDir; 58 } 59 60 64 public File getFile() { 65 return file; 66 } 67 68 72 public void setFile(File file) { 73 this.file = file; 74 } 75 76 79 public String toString() { 80 StringBuffer buf = new StringBuffer (30); 81 buf.append("\nFile: " + ((file != null)?file.getAbsolutePath():"null")); return buf.toString(); 83 } 84 85 public AnnotateLine createAnnotateLine() { 86 return new AnnotateLine(); 87 } 88 89 public void addLine(AnnotateLine line) { 90 linesList.add(line); 91 } 92 93 public AnnotateLine getFirstLine() { 94 if (linesList == null) { 95 linesList = createLinesList(); 96 } 97 iterator = linesList.iterator(); 98 return getNextLine(); 99 } 100 101 public AnnotateLine getNextLine() { 102 if (iterator == null) { 103 return null; 104 } 105 if (!iterator.hasNext()) { 106 return null; 107 } 108 return (AnnotateLine)iterator.next(); 109 } 110 111 114 protected void addToTempFile(String line) throws IOException { 115 if (tempOutStream == null) { 116 try { 117 tempFile = File.createTempFile("ann", ".cvs", tempDir); tempFile.deleteOnExit(); 119 tempOutStream = new BufferedOutputStream( 120 new FileOutputStream(tempFile)); 121 } 122 catch (IOException ex) { 123 } 125 } 126 tempOutStream.write(line.getBytes()); 127 tempOutStream.write('\n'); 128 } 129 130 protected void closeTempFile() throws IOException { 131 if (tempOutStream == null) { 132 return; 133 } 134 try { 135 tempOutStream.flush(); 136 } finally { 137 tempOutStream.close(); 138 } 139 } 140 141 public File getTempFile() { 142 return tempFile; 143 } 144 145 private List createLinesList() { 146 List toReturn = new LinkedList(); 147 BufferedReader reader = null; 148 if (tempFile == null) { 149 return toReturn; 150 } 151 try { 152 reader = new BufferedReader(new FileReader(tempFile)); 153 String line = reader.readLine(); 154 int lineNum = 1; 155 while (line != null) { 156 AnnotateLine annLine = AnnotateBuilder.processLine(line); 157 if (annLine != null) { 158 annLine.setLineNum(lineNum); 159 toReturn.add(annLine); 160 lineNum++; 161 } 162 line = reader.readLine(); 163 } 164 } 165 catch (IOException exc) { 166 } 167 finally { 168 try { 169 if (reader != null) { 170 reader.close(); 171 } 172 } 173 catch (IOException ex2) { 174 } 175 } 176 return toReturn; 177 } 178 179 } 180 | Popular Tags |