1 /* 2 * Created on Jan 19, 2007 3 * Created by Paul Gardner 4 * Copyright (C) Azureus Software, Inc, All Rights Reserved. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License 8 * as published by the Free Software Foundation; either version 2 9 * of the License, or (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 */ 19 20 21 package com.aelitis.azureus.core.peermanager.messaging.azureus; 22 23 import java.util.HashMap; 24 import java.util.Map; 25 26 import org.gudy.azureus2.core3.util.DirectByteBuffer; 27 28 import com.aelitis.azureus.core.peermanager.messaging.Message; 29 import com.aelitis.azureus.core.peermanager.messaging.MessageException; 30 import com.aelitis.azureus.core.peermanager.messaging.MessagingUtil; 31 32 public class 33 AZStatReply 34 implements AZMessage 35 { 36 private final byte version; 37 private DirectByteBuffer buffer = null; 38 39 private Map reply; 40 41 public AZStatReply( Map _reply, byte _version )42 AZStatReply( 43 Map _reply, 44 byte _version ) 45 { 46 reply = _reply; 47 version = _version; 48 } 49 50 public String getID()51 getID() 52 { 53 return( AZMessage.ID_AZ_STAT_REPLY ); 54 } 55 56 public byte[] getIDBytes()57 getIDBytes() 58 { 59 return( AZMessage.ID_AZ_STAT_REPLY_BYTES ); 60 } 61 62 public String getFeatureID()63 getFeatureID() 64 { 65 return( AZMessage.AZ_FEATURE_ID ); 66 } 67 68 public int getFeatureSubID()69 getFeatureSubID() 70 { 71 return( AZMessage.SUBID_ID_AZ_STAT_REPLY ); 72 } 73 74 public int getType()75 getType() 76 { 77 return( Message.TYPE_PROTOCOL_PAYLOAD ); 78 } 79 getVersion()80 public byte getVersion() { return version; }; 81 82 public String getDescription()83 getDescription() 84 { 85 return( getID() + ": " + reply ); 86 } 87 88 public Map getReply()89 getReply() 90 { 91 return( reply ); 92 } 93 94 public DirectByteBuffer[] getData()95 getData() 96 { 97 if ( buffer == null ){ 98 99 Map map = new HashMap(); 100 101 map.put( "reply", reply ); 102 103 buffer = MessagingUtil.convertPayloadToBencodedByteStream( map, DirectByteBuffer.AL_MSG ); 104 } 105 106 return new DirectByteBuffer[]{ buffer }; 107 } 108 109 public Message deserialize( DirectByteBuffer data, byte version )110 deserialize( 111 DirectByteBuffer data, 112 byte version ) 113 114 throws MessageException 115 { 116 Map payload = MessagingUtil.convertBencodedByteStreamToPayload( data, 1, getID() ); 117 118 Map reply = (Map)payload.get( "reply" ); 119 120 return( new AZStatReply( reply, version )); 121 } 122 123 public void destroy()124 destroy() 125 { 126 if ( buffer != null ){ 127 128 buffer.returnToPool(); 129 } 130 } 131 }