/** * Transmit a text file to the server, using the standard CVS protocol conventions. CR/LFs are * converted to the Unix format. * * @param file the file to transmit * @param dos the data outputstream on which to transmit the file */ @Override public void transmitTextFile(File file, LoggedDataOutputStream dos) throws IOException { if (file == null || !file.exists()) { throw new IllegalArgumentException( "File is either null or " + "does not exist. Cannot transmit."); } File fileToSend = file; final TransmitTextFilePreprocessor transmitTextFilePreprocessor = getTransmitTextFilePreprocessor(); if (transmitTextFilePreprocessor != null) { fileToSend = transmitTextFilePreprocessor.getPreprocessedTextFile(file); } BufferedInputStream bis = null; try { // first write the length of the file long length = fileToSend.length(); dos.writeBytes(getLengthString(length), "US-ASCII"); bis = new BufferedInputStream(new FileInputStream(fileToSend)); // now transmit the file itself byte[] chunk = new byte[CHUNK_SIZE]; while (length > 0) { int bytesToRead = length >= CHUNK_SIZE ? CHUNK_SIZE : (int) length; int count = bis.read(chunk, 0, bytesToRead); if (count == -1) { throw new IOException("Unexpected end of stream from " + fileToSend + "."); } length -= count; dos.write(chunk, 0, count); } dos.flush(); } finally { if (bis != null) { try { bis.close(); } catch (IOException ex) { // ignore } } if (transmitTextFilePreprocessor != null) { transmitTextFilePreprocessor.cleanup(fileToSend); } } }
/** * Sets the global options. This can be useful to detect, whether local files should be made * read-only. */ @Override public void setGlobalOptions(GlobalOptions globalOptions) { BugLog.getInstance().assertNotNull(globalOptions); this.globalOptions = globalOptions; transmitTextFilePreprocessor.setTempDir(globalOptions.getTempDir()); }