1 19 20 package org.netbeans.lib.cvsclient.response; 21 22 import java.io.*; 23 24 import org.netbeans.lib.cvsclient.event.*; 25 import org.netbeans.lib.cvsclient.util.*; 26 27 33 class MessageBinaryResponse implements Response { 34 35 private static final int CHUNK_SIZE = 1024 * 256; 37 public MessageBinaryResponse() { 38 } 40 41 47 public void process(LoggedDataInputStream dis, ResponseServices services) 48 throws ResponseException { 49 try { 50 String numBytesStr = dis.readLine(); 51 int numBytes; 52 try { 53 numBytes = Integer.parseInt(numBytesStr); 54 } catch (NumberFormatException nfex) { 55 throw new ResponseException(nfex); 56 } 57 int chunk = Math.min(numBytes, CHUNK_SIZE); 58 byte[] bytes = new byte[chunk]; 59 while (numBytes > 0) { 60 int len = dis.read(bytes, 0, chunk); 61 if (len == -1) { 62 throw new ResponseException("EOF", ResponseException.getLocalMessage("CommandException.EndOfFile", null)); } 64 numBytes -= len; 65 chunk = Math.min(numBytes, CHUNK_SIZE); 66 BinaryMessageEvent event = new BinaryMessageEvent(this, bytes, len); 67 services.getEventManager().fireCVSEvent(event); 68 } 69 } 70 catch (EOFException ex) { 71 throw new ResponseException(ex, ResponseException.getLocalMessage("CommandException.EndOfFile", null)); } 73 catch (IOException ex) { 74 throw new ResponseException(ex); 75 } 76 } 77 78 83 public boolean isTerminalResponse() { 84 return false; 85 } 86 } | Popular Tags |