1 /* 2 * Created on Feb 11, 2005 3 * Created by Alon Rohter 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 package org.gudy.azureus2.plugins.messaging; 21 22 import java.io.IOException; 23 import java.nio.ByteBuffer; 24 25 import org.gudy.azureus2.plugins.network.Transport; 26 27 28 /** 29 * Decodes a message stream into separate messages. 30 */ 31 public interface MessageStreamDecoder { 32 /** 33 * Decode message stream from the given transport. 34 * @param transport to decode from 35 * @param max_bytes to decode/read from the stream 36 * @return number of bytes decoded 37 * @throws IOException on decoding error 38 */ performStreamDecode( Transport transport, int max_bytes )39 public int performStreamDecode( Transport transport, int max_bytes ) throws IOException; 40 41 /** 42 * Get the messages decoded from the transport, if any, from the last decode op. 43 * @return decoded messages, or null if no new complete messages were decoded 44 */ removeDecodedMessages()45 public Message[] removeDecodedMessages(); 46 47 /** 48 * Get the number of protocol (overhead) bytes decoded from the transport, from the last decode op. 49 * @return number of protocol bytes recevied 50 */ getProtocolBytesDecoded()51 public int getProtocolBytesDecoded(); 52 53 /** 54 * Get the number of (piece) data bytes decoded from the transport, from the last decode op. 55 * @return number of data bytes received 56 */ getDataBytesDecoded()57 public int getDataBytesDecoded(); 58 59 /** 60 * Pause message decoding. 61 */ pauseDecoding()62 public void pauseDecoding(); 63 64 /** 65 * Resume message decoding. 66 */ resumeDecoding()67 public void resumeDecoding(); 68 69 /** 70 * Destroy this decoder, i.e. perform cleanup. 71 * @return any bytes already-read and still remaining within the decoder 72 */ destroy()73 public ByteBuffer destroy(); 74 } 75