1 21 package com.db4o.cs.messages; 22 23 import java.io.File ; 24 import java.io.FileInputStream ; 25 import java.io.IOException ; 26 27 import com.db4o.*; 28 import com.db4o.cs.*; 29 import com.db4o.ext.Status; 30 import com.db4o.foundation.network.YapSocket; 31 32 33 public class MReadBlob extends MsgBlob { 34 public void processClient(YapSocket sock) throws IOException { 35 Msg message = Msg.readMessage(transaction(), sock); 36 if (message.equals(Msg.LENGTH)) { 37 try { 38 _currentByte = 0; 39 _length = message.payLoad().readInt(); 40 _blob.getStatusFrom(this); 41 _blob.setStatus(Status.PROCESSING); 42 copy(sock,this._blob.getClientOutputStream(),_length,true); 43 message = Msg.readMessage(transaction(), sock); 44 if (message.equals(Msg.OK)) { 45 this._blob.setStatus(Status.COMPLETED); 46 } else { 47 this._blob.setStatus(Status.ERROR); 48 } 49 } catch (Exception e) { 50 } 51 } else if (message.equals(Msg.ERROR)) { 52 this._blob.setStatus(Status.ERROR); 53 } 54 55 } 56 public boolean processAtServer(YapServerThread serverThread) { 57 YapStream stream = stream(); 58 try { 59 BlobImpl blobImpl = this.serverGetBlobImpl(); 60 if (blobImpl != null) { 61 blobImpl.setTrans(transaction()); 62 File file = blobImpl.serverFile(null, false); 63 int length = (int) file.length(); 64 YapSocket sock = serverThread.socket(); 65 Msg.LENGTH.getWriterForInt(transaction(), length).write(stream, sock); 66 FileInputStream fin = new FileInputStream (file); 67 copy(fin,sock,false); 68 sock.flush(); 69 Msg.OK.write(stream, sock); 70 } 71 } catch (Exception e) { 72 serverThread.write(Msg.ERROR); 73 } 74 return true; 75 } 76 } | Popular Tags |