1 19 package org.netbeans.lib.cvsclient.command; 20 21 import java.io.*; 22 23 import org.netbeans.lib.cvsclient.event.*; 24 25 32 public class PipedFilesBuilder implements Builder, BinaryBuilder { 33 34 private static final String ERR_START = "======="; private static final String ERR_CHECK = "Checking out "; private static final String ERR_RCS = "RCS: "; private static final String ERR_VERS = "VERS: "; private static final String EXAM_DIR = ": Updating"; 40 private static final byte [] lineSeparator = System.getProperty("line.separator").getBytes(); 41 42 45 private PipedFileInformation fileInformation; 46 47 50 private EventManager eventManager; 51 52 56 private String fileDirectory; 57 58 private BuildableCommand command; 59 60 private TemporaryFileCreator tempFileCreator; 61 62 65 public PipedFilesBuilder(EventManager eventManager, 66 BuildableCommand command, 67 TemporaryFileCreator tempFileCreator) { 68 this.eventManager = eventManager; 69 this.command = command; 70 this.tempFileCreator = tempFileCreator; 71 } 72 73 public void outputDone() { 74 if (fileInformation == null) { 75 return; 76 } 77 78 try { 79 fileInformation.closeTempFile(); 80 } 81 catch (IOException exc) { 82 } 84 eventManager.fireCVSEvent(new FileInfoEvent(this, fileInformation)); 85 fileInformation = null; 86 } 87 88 public void parseBytes(byte[] bytes, int len) { 89 if (fileInformation == null) { 90 try { 93 fileInformation = new PipedFileInformation(File.createTempFile("checkout", null)); 94 } catch (IOException e) { 95 e.printStackTrace(); 96 } 97 } 98 99 try { 100 fileInformation.addToTempFile(bytes, len); 101 } 102 catch (IOException exc) { 103 outputDone(); 104 } 105 } 106 107 public void parseLine(String line, boolean isErrorMessage) { 108 if (isErrorMessage) { 109 if (line.indexOf(EXAM_DIR) >= 0) { 110 fileDirectory = line.substring(line.indexOf(EXAM_DIR) + EXAM_DIR.length()).trim(); 111 } 112 else if (line.startsWith(ERR_CHECK)) { 113 processFile(line); 114 } 115 else if (line.startsWith(ERR_RCS)) { 116 if (fileInformation != null) { 117 String repositoryName = 118 line.substring(ERR_RCS.length()).trim(); 119 fileInformation.setRepositoryFileName(repositoryName); 120 } 121 } 122 else if (line.startsWith(ERR_VERS)) { 123 if (fileInformation != null) { 124 String repositoryRevision = 125 line.substring(ERR_RCS.length()).trim(); 126 fileInformation.setRepositoryRevision(repositoryRevision); 127 } 128 } 129 } 131 else { 132 if (fileInformation == null) { 133 try { 136 fileInformation = new PipedFileInformation(File.createTempFile("checkout", null)); 137 } catch (IOException e) { 138 e.printStackTrace(); 139 } 140 } 141 if (fileInformation != null) { 142 try { 143 fileInformation.addToTempFile(line.getBytes("ISO-8859-1")); fileInformation.addToTempFile(lineSeparator); 145 } 146 catch (IOException exc) { 147 outputDone(); 148 } 149 } 150 } 151 } 152 153 private void processFile(String line) { 154 outputDone(); 155 String filename = line.substring(ERR_CHECK.length()); 156 try { 157 File temporaryFile = tempFileCreator.createTempFile(filename); 158 fileInformation = new PipedFileInformation(temporaryFile); 159 } 160 catch (IOException ex) { 161 fileInformation = null; 162 return; 163 } 164 fileInformation.setFile(createFile(filename)); 165 } 166 167 private File createFile(String fileName) { 168 File file = new File(command.getLocalDirectory(), fileName); 169 return file; 170 } 171 172 public void parseEnhancedMessage(String key, Object value) { 173 } 174 } 175 | Popular Tags |