1 22 package org.netbeans.lib.cvsclient.response; 23 24 import java.io.*; 25 26 import org.netbeans.lib.cvsclient.util.*; 27 28 35 class TemplateResponse 36 implements Response { 37 40 44 45 48 protected String localPath; 49 50 53 protected String repositoryPath; 54 55 58 public TemplateResponse() { 59 } 60 61 71 72 79 public void process(LoggedDataInputStream dis, ResponseServices services) 80 throws ResponseException { 81 try { 82 localPath = dis.readLine(); 83 repositoryPath = dis.readLine(); 84 85 int length = Integer.parseInt(dis.readLine()); 86 87 final String filePath = services.convertPathname(localPath, 89 repositoryPath) + 90 "CVS/Template"; 92 OutputStream out = null; 95 File file = new File(filePath); 96 file.getParentFile().mkdirs(); 97 try { 98 out = new FileOutputStream(file); 99 out = new BufferedOutputStream(out); 100 byte[] lineSeparator = System.getProperty("line.separator").getBytes(); byte[] data = dis.readBytes(length); 102 for (int i = 0; i<data.length; i++) { 103 byte ch = data[i]; 104 if (ch == '\n') { 105 out.write(lineSeparator); 106 } else { 107 out.write(ch); 108 } 109 } 110 } catch (EOFException eof) { 111 } finally { 112 if (out != null) { 113 try { 114 out.close(); 115 } catch (IOException alreadyClosed) { 116 } 117 } 118 } 119 } 120 catch (EOFException ex) { 121 String localMessage = 122 ResponseException.getLocalMessage("CommandException.EndOfFile"); throw new ResponseException(ex, localMessage); 124 } 125 catch (IOException ex) { 126 throw new ResponseException(ex); 127 } 128 } 129 130 135 public boolean isTerminalResponse() { 136 return false; 137 } 138 } 139 | Popular Tags |