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