View Javadoc
1   // NAME
2   //      $RCSfile: StreamPortItem.java,v $
3   // DESCRIPTION
4   //      [given below in javadoc format]
5   // DELTA
6   //      $Revision: 1.4 $
7   // CREATED
8   //      $Date: 2006/02/09 14:14:50 $
9   // COPYRIGHT
10  //      Westhawk Ltd
11  // TO DO
12  //
13  
14  /*
15   * Copyright (C) 2005 - 2006 by Westhawk Ltd
16   * <a href="www.westhawk.co.uk">www.westhawk.co.uk</a>
17   *
18   * Permission to use, copy, modify, and distribute this software
19   * for any purpose and without fee is hereby granted, provided
20   * that the above copyright notices appear in all copies and that
21   * both the copyright notice and this permission notice appear in
22   * supporting documentation.
23   * This software is provided "as is" without express or implied
24   * warranty.
25   * author <a href="mailto:snmp@westhawk.co.uk">Tim Panton</a>
26   */
27  
28  package uk.co.westhawk.snmp.net;
29  
30  /*-
31   * ╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲
32   * SNMP Java Client
33   * ჻჻჻჻჻჻
34   * Copyright 2023 MetricsHub, Westhawk
35   * ჻჻჻჻჻჻
36   * This program is free software: you can redistribute it and/or modify
37   * it under the terms of the GNU Lesser General Public License as
38   * published by the Free Software Foundation, either version 3 of the
39   * License, or (at your option) any later version.
40   *
41   * This program is distributed in the hope that it will be useful,
42   * but WITHOUT ANY WARRANTY; without even the implied warranty of
43   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
44   * GNU General Lesser Public License for more details.
45   *
46   * You should have received a copy of the GNU General Lesser Public
47   * License along with this program.  If not, see
48   * <http://www.gnu.org/licenses/lgpl-3.0.html>.
49   * ╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱╲╱
50   */
51  
52  import java.io.*;
53  
54  /**
55   * This is a holder class that associates the incoming packet stream
56   * with the remote port it came from.
57   *
58   * @since 4_14
59   * @author <a href="mailto:snmp@westhawk.co.uk">Birgit Arkesteijn</a>
60   * @version $Revision: 1.4 $ $Date: 2006/02/09 14:14:50 $
61   */
62  public class StreamPortItem {
63      static final String version_id = "@(#)$Id: StreamPortItem.java,v 1.4 2006/02/09 14:14:50 birgit Exp $ Copyright Westhawk Ltd";
64  
65      private String hostAddress;
66      private int port;
67      private ByteArrayInputStream stream;
68  
69      /**
70       * Constructor.
71       *
72       * @param address The host address
73       * @param newPort The remote port number
74       * @param in      The incoming message
75       */
76      public StreamPortItem(String address, int newPort, ByteArrayInputStream in) {
77          hostAddress = address;
78          port = newPort;
79          stream = in;
80      }
81  
82      /**
83       * Returns the host addres where the message came from.
84       *
85       * @return The host address
86       */
87      public String getHostAddress() {
88          return hostAddress;
89      }
90  
91      /**
92       * Returns the remote port where the message came from.
93       *
94       * @return The remote port number
95       */
96      public int getHostPort() {
97          return port;
98      }
99  
100     /**
101      * Returns incoming message (or a copy of it).
102      *
103      * @return The message
104      */
105     public ByteArrayInputStream getStream() {
106         return stream;
107     }
108 
109     /**
110      * Returns the string representation.
111      *
112      * @return The string
113      */
114     public String toString() {
115         StringBuffer buffer = new StringBuffer(getClass().getName());
116         buffer.append("[");
117         buffer.append("hostAddress=").append(hostAddress);
118         buffer.append(", hostPort=").append(port);
119         buffer.append(", #bytes=").append(stream.available());
120         buffer.append("]");
121         return buffer.toString();
122     }
123 
124 }