|
From: <cr...@us...> - 2008-06-08 02:02:16
|
Revision: 4213
http://jnode.svn.sourceforge.net/jnode/?rev=4213&view=rev
Author: crawley
Date: 2008-06-07 19:02:10 -0700 (Sat, 07 Jun 2008)
Log Message:
-----------
Style fixes
Modified Paths:
--------------
trunk/net/src/net/org/jnode/net/HardwareAddress.java
trunk/net/src/net/org/jnode/net/InvalidLayerException.java
trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java
trunk/net/src/net/org/jnode/net/LayerHeader.java
trunk/net/src/net/org/jnode/net/LinkLayer.java
trunk/net/src/net/org/jnode/net/LinkLayerHeader.java
trunk/net/src/net/org/jnode/net/NetPermission.java
trunk/net/src/net/org/jnode/net/NetworkLayer.java
trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java
trunk/net/src/net/org/jnode/net/NetworkLayerManager.java
trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java
trunk/net/src/net/org/jnode/net/ProtocolAddress.java
trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java
trunk/net/src/net/org/jnode/net/Resolver.java
trunk/net/src/net/org/jnode/net/SocketBuffer.java
trunk/net/src/net/org/jnode/net/TransportLayer.java
trunk/net/src/net/org/jnode/net/arp/ARPCache.java
trunk/net/src/net/org/jnode/net/arp/ARPCacheEntry.java
trunk/net/src/net/org/jnode/net/arp/ARPConstants.java
trunk/net/src/net/org/jnode/net/arp/ARPHeader.java
trunk/net/src/net/org/jnode/net/arp/ARPNetworkLayer.java
trunk/net/src/net/org/jnode/net/arp/ARPStatistics.java
trunk/net/src/net/org/jnode/net/arp/RARPNetworkLayer.java
trunk/net/src/net/org/jnode/net/command/ArpCommand.java
trunk/net/src/net/org/jnode/net/command/BootpCommand.java
trunk/net/src/net/org/jnode/net/command/DhcpCommand.java
trunk/net/src/net/org/jnode/net/command/IfconfigCommand.java
trunk/net/src/net/org/jnode/net/command/NetstatCommand.java
trunk/net/src/net/org/jnode/net/command/PingCommand.java
trunk/net/src/net/org/jnode/net/command/ResolverCommand.java
trunk/net/src/net/org/jnode/net/command/RouteCommand.java
trunk/net/src/net/org/jnode/net/command/RpcInfoCommand.java
trunk/net/src/net/org/jnode/net/command/TcpInoutCommand.java
trunk/net/src/net/org/jnode/net/command/TftpCommand.java
trunk/net/src/net/org/jnode/net/command/WLanCtlCommand.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetAddress.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetConstants.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetHeader.java
trunk/net/src/net/org/jnode/net/ethernet/EthernetUtils.java
trunk/net/src/net/org/jnode/net/help/argument/HostArgument.java
trunk/net/src/net/org/jnode/net/help/argument/NetworkArgument.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Address.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4AddressAndMask.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Constants.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4ControlBlock.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4ControlBlockList.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4FragmentList.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Header.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4IfAddress.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Protocol.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4ProtocolAddressInfo.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Route.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4RoutingTable.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Service.java
trunk/net/src/net/org/jnode/net/ipv4/IPv4Utils.java
trunk/net/src/net/org/jnode/net/ipv4/util/ResolverImpl.java
Modified: trunk/net/src/net/org/jnode/net/HardwareAddress.java
===================================================================
--- trunk/net/src/net/org/jnode/net/HardwareAddress.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/HardwareAddress.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -27,44 +27,44 @@
*/
public interface HardwareAddress {
- /**
- * Is this address equal to the given address.
- * @param o
- */
- public boolean equals(HardwareAddress o);
-
- /**
- * Gets the length of this address in bytes
- */
- public int getLength();
-
- /**
- * Gets the address-byte at a given index
- * @param index
- */
- public byte get(int index);
-
- /**
- * Write this address to a given offset in the given buffer
- * @param skbuf
- * @param skbufOffset
- */
- public void writeTo(SocketBuffer skbuf, int skbufOffset);
-
- /**
- * Is this a broadcast address?
- */
- public boolean isBroadcast();
+ /**
+ * Is this address equal to the given address.
+ * @param o
+ */
+ public boolean equals(HardwareAddress o);
- /**
- * Gets the default broadcast address for this kind of hardware address.
- */
- public HardwareAddress getDefaultBroadcastAddress();
-
- /**
- * Gets the type of this address.
- * This type is used by (e.g.) ARP.
- */
- public int getType();
-
+ /**
+ * Gets the length of this address in bytes
+ */
+ public int getLength();
+
+ /**
+ * Gets the address-byte at a given index
+ * @param index
+ */
+ public byte get(int index);
+
+ /**
+ * Write this address to a given offset in the given buffer
+ * @param skbuf
+ * @param skbufOffset
+ */
+ public void writeTo(SocketBuffer skbuf, int skbufOffset);
+
+ /**
+ * Is this a broadcast address?
+ */
+ public boolean isBroadcast();
+
+ /**
+ * Gets the default broadcast address for this kind of hardware address.
+ */
+ public HardwareAddress getDefaultBroadcastAddress();
+
+ /**
+ * Gets the type of this address.
+ * This type is used by (e.g.) ARP.
+ */
+ public int getType();
+
}
Modified: trunk/net/src/net/org/jnode/net/InvalidLayerException.java
===================================================================
--- trunk/net/src/net/org/jnode/net/InvalidLayerException.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/InvalidLayerException.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,18 +28,18 @@
*/
public class InvalidLayerException extends SocketException {
- /**
- *
- */
- public InvalidLayerException() {
- super();
- }
+ /**
+ *
+ */
+ public InvalidLayerException() {
+ super();
+ }
- /**
- * @param message
- */
- public InvalidLayerException(String message) {
- super(message);
- }
+ /**
+ * @param message
+ */
+ public InvalidLayerException(String message) {
+ super(message);
+ }
}
Modified: trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LayerAlreadyRegisteredException.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,36 +28,34 @@
*/
public class LayerAlreadyRegisteredException extends SocketException {
- /**
- *
- */
- public LayerAlreadyRegisteredException() {
- super();
- }
+ /**
+ *
+ */
+ public LayerAlreadyRegisteredException() {
+ super();
+ }
- /**
- * @param message
- * @param cause
- */
- public LayerAlreadyRegisteredException(
- String message,
- Throwable cause) {
- super(message);
- initCause(cause);
- }
+ /**
+ * @param message
+ * @param cause
+ */
+ public LayerAlreadyRegisteredException(String message, Throwable cause) {
+ super(message);
+ initCause(cause);
+ }
- /**
- * @param cause
- */
- public LayerAlreadyRegisteredException(Throwable cause) {
- super();
- initCause(cause);
- }
+ /**
+ * @param cause
+ */
+ public LayerAlreadyRegisteredException(Throwable cause) {
+ super();
+ initCause(cause);
+ }
- /**
- * @param s
- */
- public LayerAlreadyRegisteredException(String s) {
- super(s);
- }
+ /**
+ * @param s
+ */
+ public LayerAlreadyRegisteredException(String s) {
+ super(s);
+ }
}
Modified: trunk/net/src/net/org/jnode/net/LayerHeader.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LayerHeader.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LayerHeader.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -30,25 +30,27 @@
* @see org.jnode.net.TransportLayerHeader
*/
public interface LayerHeader {
-
- /**
- * Gets the length of this header in bytes
- */
- public int getLength();
- /**
- * Prefix this header to the front of the given buffer
- * @param skbuf
- */
- public void prefixTo(SocketBuffer skbuf);
-
- /**
- * Finalize the header in the given buffer.
- * This method is called when all layers have set their header data
- * and can be used e.g. to update checksum values.
- *
- * @param skbuf The buffer
- * @param offset The offset to the first byte (in the buffer) of this header (since low layer headers are already prefixed)
- */
- public void finalizeHeader(SocketBuffer skbuf, int offset);
+ /**
+ * Gets the length of this header in bytes
+ */
+ public int getLength();
+
+ /**
+ * Prefix this header to the front of the given buffer
+ *
+ * @param skbuf
+ */
+ public void prefixTo(SocketBuffer skbuf);
+
+ /**
+ * Finalize the header in the given buffer. This method is called when all
+ * layers have set their header data and can be used e.g. to update checksum
+ * values.
+ *
+ * @param skbuf The buffer
+ * @param offset The offset to the first byte (in the buffer) of this header
+ * (since low layer headers are already prefixed)
+ */
+ public void finalizeHeader(SocketBuffer skbuf, int offset);
}
Modified: trunk/net/src/net/org/jnode/net/LinkLayer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LinkLayer.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LinkLayer.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -25,28 +25,28 @@
/**
* OSI datalink layers must implement this interface.
- *
+ *
* @author epr
*/
public interface LinkLayer {
-
- /**
- * Gets the name of this layer
- */
- public String getName();
-
- /**
- * Gets the type of frames this layer handles
- */
- public int getType();
-
- /**
- * Process a packet that has been received and matches the type of this
- * layer.
- * @param skbuf
- * @throws SocketException
- */
- public void receive(SocketBuffer skbuf)
- throws SocketException;
+ /**
+ * Gets the name of this layer
+ */
+ public String getName();
+
+ /**
+ * Gets the type of frames this layer handles
+ */
+ public int getType();
+
+ /**
+ * Process a packet that has been received and matches the type of this
+ * layer.
+ *
+ * @param skbuf
+ * @throws SocketException
+ */
+ public void receive(SocketBuffer skbuf) throws SocketException;
+
}
Modified: trunk/net/src/net/org/jnode/net/LinkLayerHeader.java
===================================================================
--- trunk/net/src/net/org/jnode/net/LinkLayerHeader.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/LinkLayerHeader.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,15 +28,15 @@
* @see org.jnode.net.LinkLayer
*/
public interface LinkLayerHeader extends LayerHeader {
-
- /**
- * Gets the source address of the packet described in this header
- */
- public HardwareAddress getSourceAddress();
- /**
- * Gets the source address of the packet described in this header
- */
- public HardwareAddress getDestinationAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public HardwareAddress getSourceAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public HardwareAddress getDestinationAddress();
+
}
Modified: trunk/net/src/net/org/jnode/net/NetPermission.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetPermission.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetPermission.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -35,7 +35,7 @@
public NetPermission(String name) {
super(name);
}
-
+
/**
* @param name
* @param actions
Modified: trunk/net/src/net/org/jnode/net/NetworkLayer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetworkLayer.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetworkLayer.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -34,66 +34,70 @@
* @author epr
*/
public interface NetworkLayer {
-
- /**
- * Gets the name of this type
- */
- public String getName();
-
- /**
- * Gets the protocol ID this layer handles
- */
- public int getProtocolID();
-
- /**
- * Can this packet type process packets received from the given device?
- */
- public boolean isAllowedForDevice(Device dev);
-
- /**
- * Process a packet that has been received and matches getType()
- * @param skbuf
- * @param deviceAPI
- * @throws SocketException
- */
- public void receive(SocketBuffer skbuf, NetDeviceAPI deviceAPI)
- throws SocketException;
-
- /**
- * Gets the statistics of this protocol
- */
- public Statistics getStatistics();
- /**
- * Register a transportlayer as possible destination of packets received by this networklayer
- * @param layer
- */
- public void registerTransportLayer(TransportLayer layer)
- throws LayerAlreadyRegisteredException, InvalidLayerException;
-
- /**
- * Unregister a transportlayer
- * @param layer
- */
- public void unregisterTransportLayer(TransportLayer layer);
-
- /**
- * Gets all registered transport-layers
- */
- public Collection<TransportLayer> getTransportLayers();
-
- /**
- * Gets a registered transportlayer by its protocol ID.
- * @param protocolID
- * @throws NoSuchProtocolException No protocol with the given ID was found.
- */
- public TransportLayer getTransportLayer(int protocolID)
- throws NoSuchProtocolException;
+ /**
+ * Gets the name of this type
+ */
+ public String getName();
- /**
- * Gets the protocol addresses for a given name, or null if not found.
- * @param hostname
- * @return
- */
+ /**
+ * Gets the protocol ID this layer handles
+ */
+ public int getProtocolID();
+
+ /**
+ * Can this packet type process packets received from the given device?
+ */
+ public boolean isAllowedForDevice(Device dev);
+
+ /**
+ * Process a packet that has been received and matches getType()
+ *
+ * @param skbuf
+ * @param deviceAPI
+ * @throws SocketException
+ */
+ public void receive(SocketBuffer skbuf, NetDeviceAPI deviceAPI) throws SocketException;
+
+ /**
+ * Gets the statistics of this protocol
+ */
+ public Statistics getStatistics();
+
+ /**
+ * Register a transportlayer as possible destination of packets received by
+ * this networklayer
+ *
+ * @param layer
+ */
+ public void registerTransportLayer(TransportLayer layer)
+ throws LayerAlreadyRegisteredException, InvalidLayerException;
+
+ /**
+ * Unregister a transportlayer
+ *
+ * @param layer
+ */
+ public void unregisterTransportLayer(TransportLayer layer);
+
+ /**
+ * Gets all registered transport-layers
+ */
+ public Collection<TransportLayer> getTransportLayers();
+
+ /**
+ * Gets a registered transportlayer by its protocol ID.
+ *
+ * @param protocolID
+ * @throws NoSuchProtocolException No protocol with the given ID was found.
+ */
+ public TransportLayer getTransportLayer(int protocolID) throws NoSuchProtocolException;
+
+ /**
+ * Gets the protocol addresses for a given name, or null if not found.
+ *
+ * @param hostname
+ * @return
+ */
public ProtocolAddress[] getHostByName(String hostname);
}
Modified: trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetworkLayerHeader.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -29,13 +29,13 @@
*/
public interface NetworkLayerHeader extends LayerHeader {
- /**
- * Gets the source address of the packet described in this header
- */
- public ProtocolAddress getSourceAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public ProtocolAddress getSourceAddress();
- /**
- * Gets the source address of the packet described in this header
- */
- public ProtocolAddress getDestinationAddress();
+ /**
+ * Gets the source address of the packet described in this header
+ */
+ public ProtocolAddress getDestinationAddress();
}
Modified: trunk/net/src/net/org/jnode/net/NetworkLayerManager.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NetworkLayerManager.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NetworkLayerManager.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -26,44 +26,42 @@
import org.jnode.driver.net.NetworkException;
/**
- * This interface must be implemented by the network service of the JNode kernel.
- * It contains methods to register/unregister and obtain NetworkLayers, and
- * it is used by Network drivers to deliver receive packets.
- * <p/>
- * The implementation of this interface must be obtained by invoking a lookup
- * of {@link #NAME} on {@link org.jnode.naming.InitialNaming}.
+ * This interface must be implemented by the network service of the JNode
+ * kernel. It contains methods to register/unregister and obtain NetworkLayers,
+ * and it is used by Network drivers to deliver receive packets. <p/> The
+ * implementation of this interface must be obtained by invoking a lookup of
+ * {@link #NAME} on {@link org.jnode.naming.InitialNaming}.
*
* @author epr
* @see org.jnode.driver.net.NetDeviceAPI
*/
public interface NetworkLayerManager {
- /** Name used to bind the ptm in the InitialNaming namespace */
- public static final Class<NetworkLayerManager> NAME = NetworkLayerManager.class;//"system/net/networklayermanager";
+ /** Name used to bind the ptm in the InitialNaming namespace */
+ public static final Class<NetworkLayerManager> NAME = NetworkLayerManager.class;
+
+ /**
+ * Get all register packet types.
+ *
+ * @return A collection of PacketType instances
+ */
+ public Collection<NetworkLayer> getNetworkLayers();
- /**
- * Get all register packet types.
- * @return A collection of PacketType instances
- */
- public Collection<NetworkLayer> getNetworkLayers();
-
- /**
- * Gets the packet type for a given protocol ID
- * @param protocolID
- * @throws NoSuchProtocolException
- */
- public NetworkLayer getNetworkLayer(int protocolID)
- throws NoSuchProtocolException;
-
- /**
- * Process a packet that has been received.
- * The receive method of all those packettypes that have a matching type
- * and allow the device(of the packet) is called.
- * The packet is cloned if more then 1 packettypes want to receive the
- * packet.
- *
- * @param skbuf
- */
- public void receive(SocketBuffer skbuf)
- throws NetworkException;
+ /**
+ * Gets the packet type for a given protocol ID
+ *
+ * @param protocolID
+ * @throws NoSuchProtocolException
+ */
+ public NetworkLayer getNetworkLayer(int protocolID) throws NoSuchProtocolException;
+
+ /**
+ * Process a packet that has been received. The receive method of all those
+ * packettypes that have a matching type and allow the device(of the packet)
+ * is called. The packet is cloned if more then 1 packettypes want to
+ * receive the packet.
+ *
+ * @param skbuf
+ */
+ public void receive(SocketBuffer skbuf) throws NetworkException;
}
Modified: trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java
===================================================================
--- trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/NoSuchProtocolException.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -28,17 +28,17 @@
*/
public class NoSuchProtocolException extends SocketException {
- /**
- *
- */
- public NoSuchProtocolException() {
- super();
- }
+ /**
+ *
+ */
+ public NoSuchProtocolException() {
+ super();
+ }
- /**
- * @param message
- */
- public NoSuchProtocolException(String message) {
- super(message);
- }
+ /**
+ * @param message
+ */
+ public NoSuchProtocolException(String message) {
+ super(message);
+ }
}
Modified: trunk/net/src/net/org/jnode/net/ProtocolAddress.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ProtocolAddress.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/ProtocolAddress.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -29,44 +29,44 @@
*/
public interface ProtocolAddress {
- /**
- * Is this address equal to the given address.
- * @param o
- */
- public boolean equals(ProtocolAddress o);
-
- /**
- * Gets the length of this address in bytes
- */
- public int getLength();
-
- /**
- * Gets the address-byte at a given index
- * @param index
- */
- public byte get(int index);
-
- /**
- * Write this address to a given offset in the given buffer
- * @param skbuf
- * @param skbufOffset
- */
- public void writeTo(SocketBuffer skbuf, int skbufOffset);
+ /**
+ * Is this address equal to the given address.
+ * @param o
+ */
+ public boolean equals(ProtocolAddress o);
- /**
- * Gets the type of this address.
- * This type is used by (e.g.) ARP.
- */
- public int getType();
+ /**
+ * Gets the length of this address in bytes
+ */
+ public int getLength();
- /**
- * Convert to a java.net.InetAddress
- * @see java.net.InetAddress
- * @return This address as java.net.InetAddress
- */
- public InetAddress toInetAddress();
+ /**
+ * Gets the address-byte at a given index
+ * @param index
+ */
+ public byte get(int index);
/**
+ * Write this address to a given offset in the given buffer
+ * @param skbuf
+ * @param skbufOffset
+ */
+ public void writeTo(SocketBuffer skbuf, int skbufOffset);
+
+ /**
+ * Gets the type of this address.
+ * This type is used by (e.g.) ARP.
+ */
+ public int getType();
+
+ /**
+ * Convert to a java.net.InetAddress
+ * @see java.net.InetAddress
+ * @return This address as java.net.InetAddress
+ */
+ public InetAddress toInetAddress();
+
+ /**
* Convert to a new byte array.
* @return This address as byte array.
*/
Modified: trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java
===================================================================
--- trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/ProtocolAddressInfo.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -33,26 +33,26 @@
*/
public interface ProtocolAddressInfo {
- /**
- * Is the given address one of the addresses of this object?
- * @param address
- */
- public boolean contains(ProtocolAddress address);
-
- /**
- * Is the given address one of the addresses of this object?
- * @param address
- */
- public boolean contains(InetAddress address);
-
- /**
- * Gets the default protocol address
- */
- public ProtocolAddress getDefaultAddress();
+ /**
+ * Is the given address one of the addresses of this object?
+ * @param address
+ */
+ public boolean contains(ProtocolAddress address);
- /**
- * Gets a collection of all protocol addresses of this interface.
- * @return A Set of ProtocolAddress instances
- */
- public Set<ProtocolAddress> addresses();
+ /**
+ * Is the given address one of the addresses of this object?
+ * @param address
+ */
+ public boolean contains(InetAddress address);
+
+ /**
+ * Gets the default protocol address
+ */
+ public ProtocolAddress getDefaultAddress();
+
+ /**
+ * Gets a collection of all protocol addresses of this interface.
+ * @return A Set of ProtocolAddress instances
+ */
+ public Set<ProtocolAddress> addresses();
}
Modified: trunk/net/src/net/org/jnode/net/Resolver.java
===================================================================
--- trunk/net/src/net/org/jnode/net/Resolver.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/Resolver.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -27,24 +27,25 @@
* @author epr
*/
public interface Resolver {
-
- /**
- * Gets the address(es) of the given hostname.
- * @param hostname
- * @return All addresses of the given hostname. The returned array is at least 1 address long.
- * @throws UnknownHostException
- */
- public ProtocolAddress[] getByName(String hostname)
- throws UnknownHostException;
- /**
- * Gets the hostname of the given address.
- * @param address
- * @return All hostnames of the given hostname. The returned array is at least 1 hostname long.
- * @throws UnknownHostException
- */
- public String[] getByAddress(ProtocolAddress address)
- throws UnknownHostException;
-
+ /**
+ * Gets the address(es) of the given hostname.
+ *
+ * @param hostname
+ * @return All addresses of the given hostname. The returned array is at
+ * least 1 address long.
+ * @throws UnknownHostException
+ */
+ public ProtocolAddress[] getByName(String hostname) throws UnknownHostException;
+ /**
+ * Gets the hostname of the given address.
+ *
+ * @param address
+ * @return All hostnames of the given hostname. The returned array is at
+ * least 1 hostname long.
+ * @throws UnknownHostException
+ */
+ public String[] getByAddress(ProtocolAddress address) throws UnknownHostException;
+
}
Modified: trunk/net/src/net/org/jnode/net/SocketBuffer.java
===================================================================
--- trunk/net/src/net/org/jnode/net/SocketBuffer.java 2008-06-07 23:47:31 UTC (rev 4212)
+++ trunk/net/src/net/org/jnode/net/SocketBuffer.java 2008-06-08 02:02:10 UTC (rev 4213)
@@ -25,649 +25,672 @@
import org.jnode.driver.Device;
/**
- * A SocketBuffer is container of a network packet. It enables efficient
- * storage even when various network layers prefix and/or postfix header/footers.
- * It also contains other information of a network packet, such as the headers
- * of the various network layers.
+ * A SocketBuffer is container of a network packet. It enables efficient storage
+ * even when various network layers prefix and/or postfix header/footers. It
+ * also contains other information of a network packet, such as the headers of
+ * the various network layers.
*
- * All numbers larger then a single byte written into this class are
- * converted to network byte order.
+ * All numbers larger then a single byte written into this class are converted
+ * to network byte order.
*
- * All numbers larger then a single byte read from this class are
- * converted from network byte order.
+ * All numbers larger then a single byte read from this class are converted from
+ * network byte order.
*
* @author epr
*/
public class SocketBuffer {
- private static final int INITIAL_SIZE = 256;
+ private static final int INITIAL_SIZE = 256;
- /** My logger */
- private static final Logger log = Logger.getLogger(SocketBuffer.class);
- /** Actual data */
- private byte[] data;
- /** Size of the buffer that is in use */
- private int size;
- /** Start offset in data */
- private int start;
- /** Next buffer, that is concatenated with this one */
- private SocketBuffer next;
+ /** My logger */
+ private static final Logger log = Logger.getLogger(SocketBuffer.class);
+ /** Actual data */
+ private byte[] data;
+ /** Size of the buffer that is in use */
+ private int size;
+ /** Start offset in data */
+ private int start;
+ /** Next buffer, that is concatenated with this one */
+ private SocketBuffer next;
- /** The network device who will be sending, or has received this buffer */
- private Device device;
- /** Identifying type of the packettype */
- private int protocolID;
- /** Link layer header (if any) */
- private LinkLayerHeader linkLayerHeader;
- /** Network layer header (if any) */
- private NetworkLayerHeader networkLayerHeader;
- /** Transport layer header (if any) */
- private TransportLayerHeader transportLayerHeader;
+ /** The network device who will be sending, or has received this buffer */
+ private Device device;
+ /** Identifying type of the packettype */
+ private int protocolID;
+ /** Link layer header (if any) */
+ private LinkLayerHeader linkLayerHeader;
+ /** Network layer header (if any) */
+ private NetworkLayerHeader networkLayerHeader;
+ /** Transport layer header (if any) */
+ private TransportLayerHeader transportLayerHeader;
- /**
- * Create a new instance
- */
- public SocketBuffer() {
- }
+ /**
+ * Create a new instance
+ */
+ public SocketBuffer() {
+ }
- /**
- * Create a new instance with a buffer of a given capacity
- */
- public SocketBuffer(int initialCapacity) {
- this(initialCapacity, 0);
- }
+ /**
+ * Create a new instance with a buffer of a given capacity
+ */
+ public SocketBuffer(int initialCapacity) {
+ this(initialCapacity, 0);
+ }
- /**
- * Create a new instance with a buffer of a given capacity
- */
- public SocketBuffer(int initialCapacity, int initialStart) {
- this.data = new byte[initialCapacity];
- }
+ /**
+ * Create a new instance with a buffer of a given capacity
+ */
+ public SocketBuffer(int initialCapacity, int initialStart) {
+ this.data = new byte[initialCapacity];
+ }
- /**
- * Create a clone of the data of src.
- * Other attributes are not cloned!.
- *
- * @param src
- */
- public SocketBuffer(SocketBuffer src) {
- this.start = 0;
- this.size = src.getSize();
- this.data = src.toByteArray();
- this.next = null;
- }
+ /**
+ * Create a clone of the data of src. Other attributes are not cloned!.
+ *
+ * @param src
+ */
+ public SocketBuffer(SocketBuffer src) {
+ this.start = 0;
+ this.size = src.getSize();
+ this.data = src.toByteArray();
+ this.next = null;
+ }
- /**
- * Create a new instance, using the given byte array as data.
- * No copy of the data is made!
- * @param data
- * @param offset
- * @param length
- */
- public SocketBuffer(byte[] data, int offset, int length) {
- this.data=new byte[data.length];
+ /**
+ * Create a new instance, using the given byte array as data. No copy of the
+ * data is made!
+ *
+ * @param data
+ * @param offset
+ * @param length
+ */
+ public SocketBuffer(byte[] data, int offset, int length) {
+ this.data = new byte[data.length];
System.arraycopy(data, 0, this.data, 0, data.length);
this.start = offset;
- this.size = length;
- testBuffer();
- }
+ this.size = length;
+ testBuffer();
+ }
- /**
- * Gets the network device who will be sending, or has received this buffer
- */
- public Device getDevice() {
- return device;
- }
+ /**
+ * Gets the network device who will be sending, or has received this buffer
+ */
+ public Device getDevice() {
+ return device;
+ }
- /**
- * Sets the network device who will be sending, or has received this buffer
- * @param device
- */
- public void setDevice(Device device) {
- this.device = device;
- }
+ /**
+ * Sets the network device who will be sending, or has received this buffer
+ *
+ * @param device
+ */
+ public void setDevice(Device device) {
+ this.device = device;
+ }
- /**
- * Gets the identifying type of the packettype.
- */
- public int getProtocolID() {
- return protocolID;
- }
+ /**
+ * Gets the identifying type of the packettype.
+ */
+ public int getProtocolID() {
+ return protocolID;
+ }
- /**
- * Sets the identifying type of the packettype.
- * @param i
- */
- public void setProtocolID(int i) {
- protocolID = i;
- }
+ /**
+ * Sets the identifying type of the packettype.
+ *
+ * @param i
+ */
+ public void setProtocolID(int i) {
+ protocolID = i;
+ }
- /**
- * Clear this buffer, so it can be used for another purpose
- *
- */
- public void clear() {
- size = 0;
- start = 0;
- next = null;
- protocolID = 0;
- linkLayerHeader = null;
- networkLayerHeader = null;
- transportLayerHeader = null;
- device = null;
- // preserve data (if set), we can used it again
- }
+ /**
+ * Clear this buffer, so it can be used for another purpose
+ *
+ */
+ public void clear() {
+ size = 0;
+ start = 0;
+ next = null;
+ protocolID = 0;
+ linkLayerHeader = null;
+ networkLayerHeader = null;
+ transportLayerHeader = null;
+ device = null;
+ // preserve data (if set), we can used it again
+ }
- /**
- * Insert a given number of bytes to the front of the buffer.
- * The inserted bytes are cleaned with a value of <code>(byte)0</code>.
- * @param count
- */
- public void insert(int count) {
- if (start >= count) {
- start -= count;
- size += count;
- } else {
- setSize(size + count);
- for (int i = size - 1; i >= count; i--) {
- data[start + i] = data[start + i - count];
- }
- }
- for (int i = 0; i < count; i++) {
- data[start + i] = 0;
- }
- testBuffer();
- }
+ /**
+ * Insert a given number of bytes to the front of the buffer. The inserted
+ * bytes are cleaned with a value of <code>(byte)0</code>.
+ *
+ * @param count
+ */
+ public void insert(int count) {
+ if (start >= count) {
+ start -= count;
+ size += count;
+ } else {
+ setSize(size + count);
+ for (int i = size - 1; i >= count; i--) {
+ data[start + i] = data[start + i - count];
+ }
+ }
+ for (int i = 0; i < count; i++) {
+ data[start + i] = 0;
+ }
+ testBuffer();
+ }
- /**
- * Remove a given number of bytes from the front of the buffer
- * @param count
- */
- public void pull(int count) {
- if (count > size) {
- if (next != null) {
- // Pull a bit of myself and the rest of next
- count -= size;
- start = size;
- size = 0;
- next.pull(count);
- } else {
- throw new IllegalArgumentException("Cannot pull " + count + " bytes (" + start + "," + size + ")");
- }
- } else {
- start += count;
- size -= count;
- }
- testBuffer();
- }
+ /**
+ * Remove a given number of bytes from the front of the buffer
+ *
+ * @param count
+ */
+ public void pull(int count) {
+ if (count > size) {
+ if (next != null) {
+ // Pull a bit of myself and the rest of next
+ count -= size;
+ start = size;
+ size = 0;
+ next.pull(count);
+ } else {
+ throw new IllegalArgumentException("Cannot pull " + count + " bytes (" + start +
+ "," + size + ")");
+ }
+ } else {
+ start += count;
+ size -= count;
+ }
+ testBuffer();
+ }
- /**
- * Undo a pull action.
- * This method is different from insert, as this method can only unpull
- * that what has been removed by an earlier call to pull, insert will
- * actually make new room at the head on the buffer.
- * @param count
- * @throws IllegalArgumentException It is not possible to unpull count bytes.
- */
- public void unpull(int count) {
- if (start >= count) {
- start -= count;
- size += count;
- } else {
- if (next != null) {
- // Unpull most of next and that what I can from me
- final int remaining = (count - start);
- size += start;
- start = 0;
- next.unpull(remaining);
- } else {
- throw new IllegalArgumentException("Cannot unpull " + count + " bytes (" + start + "," + size + ")");
- }
- }
- testBuffer();
- }
+ /**
+ * Undo a pull action. This method is different from insert, as this method
+ * can only unpull that what has been removed by an earlier call to pull,
+ * insert will actually make new room at the head on the buffer.
+ *
+ * @param count
+ * @throws IllegalArgumentException It is not possible to unpull count
+ * bytes.
+ */
+ public void unpull(int count) {
+ if (start >= count) {
+ start -= count;
+ size += count;
+ } else {
+ if (next != null) {
+ // Unpull most of next and that what I can from me
+ final int remaining = (count - start);
+ size += start;
+ start = 0;
+ next.unpull(remaining);
+ } else {
+ throw new IllegalArgumentException("Cannot unpull " + count + " bytes (" + start +
+ "," + size + ")");
+ }
+ }
+ testBuffer();
+ }
- /**
- * Remove data from the tail of the buffer, until size <= length.
- * If the current size < length, nothing happens.
- * @param length
- */
- public void trim(int length) {
- if (length < size) {
- // Cut the tail of myself and remove any next buffer
- size = length;
- next = null;
- } else if (length == size) {
- // Remove any next buffer
- next = null;
- } else {
- // Length > size
- if (next != null) {
- next.trim(length - size);
- }
- }
- }
+ /**
+ * Remove data from the tail of the buffer, until size <= length. If the
+ * current size < length, nothing happens.
+ *
+ * @param length
+ */
+ public void trim(int length) {
+ if (length < size) {
+ // Cut the tail of myself and remove any next buffer
+ size = length;
+ next = null;
+ } else if (length == size) {
+ // Remove any next buffer
+ next = null;
+ } else {
+ // Length > size
+ if (next != null) {
+ next.trim(length - size);
+ }
+ }
+ }
- /**
- * Insert a given number of bytes to the back of the buffer
- * @param count
- */
- public void append(int count) {
- if (next != null) {
- next.append(count);
- } else {
- setSize(size + count);
- }
- testBuffer();
- }
+ /**
+ * Insert a given number of bytes to the back of the buffer
+ *
+ * @param count
+ */
+ public void append(int count) {
+ if (next != null) {
+ next.append(count);
+ } else {
+ setSize(size + count);
+ }
+ testBuffer();
+ }
- /**
- * Insert a given number of bytes to the front of the buffer
- * @param src
- * @param srcOffset
- * @param length
- */
- public void append(byte[] src, int srcOffset, int length) {
- if (next != null) {
- next.append(src, srcOffset, length);
- } else {
- final int dstOffset = start + size;
- setSize(size + length);
- System.arraycopy(src, srcOffset, data, dstOffset, length);
- }
- testBuffer();
- }
+ /**
+ * Insert a given number of bytes to the front of the buffer
+ *
+ * @param src
+ * @param srcOffset
+ * @param length
+ */
+ public void append(byte[] src, int srcOffset, int length) {
+ if (next != null) {
+ next.append(src, srcOffset, length);
+ } else {
+ final int dstOffset = start + size;
+ setSize(size + length);
+ System.arraycopy(src, srcOffset, data, dstOffset, length);
+ }
+ testBuffer();
+ }
- /**
- * Append a complete buffer to the end of this buffer.
- * @param skbuf
- */
- public void append(SocketBuffer skbuf) {
- if (next != null) {
- next.append(skbuf);
- } else {
- next = skbuf;
- }
- testBuffer();
- }
+ /**
+ * Append a complete buffer to the end of this buffer.
+ *
+ * @param skbuf
+ */
+ public void append(SocketBuffer skbuf) {
+ if (next != null) {
+ next.append(skbuf);
+ } else {
+ next = skbuf;
+ }
+ testBuffer();
+ }
- /**
- * Append a buffer to the end of this buffer starting at the given offset
- * in the appended buffer.
- * @param skbufOffset
- * @param skbuf
- */
- public void append(int skbufOffset, SocketBuffer skbuf) {
- final byte[] src = skbuf.toByteArray();
- append(src, skbufOffset, src.length - skbufOffset);
- }
+ /**
+ * Append a buffer to the end of this buffer starting at the given offset in
+ * the appended buffer.
+ *
+ * @param skbufOffset
+ * @param skbuf
+ */
+ public void append(int skbufOffset, SocketBuffer skbuf) {
+ final byte[] src = skbuf.toByteArray();
+ append(src, skbufOffset, src.length - skbufOffset);
+ }
- /**
- * Append a buffer to the end of this buffer with only a given amount
- * of bytes.
- * The given buffer must not contain a next buffer and must have a size
- * greater or equal to length
- * @param skbuf
- */
- public void append(SocketBuffer skbuf, int length) throws IllegalArgumentException {
- if (length == 0) {
- return;
- }
- if (next != null) {
- next.append(skbuf, length);
- } else {
- if (length < 0) {
- throw new IllegalArgumentException("Length < 0");
- }
- if (skbuf.next != null) {
- throw new IllegalArgumentException("skbuf.next != null");
- }
- if (skbuf.size < length) {
- throw new IllegalArgumentException("skbuf.size < length");
- }
- next = skbuf;
- skbuf.size = length;
- }
- testBuffer();
- }
+ /**
+ * Append a buffer to the end of this buffer with only a given amount of
+ * bytes. The given buffer must not contain a next buffer and must have a
+ * size greater or equal to length
+ *
+ * @param skbuf
+ */
+ public void append(SocketBuffer skbuf, int length) throws IllegalArgumentException {
+ if (length == 0) {
+ return;
+ }
+ if (next != null) {
+ next.append(skbuf, length);
+ } else {
+ if (length < 0) {
+ throw new IllegalArgumentException("Length < 0");
+ }
+ if (skbuf.next != null) {
+ throw new IllegalArgumentException("skbuf.next != null");
+ }
+ if (skbuf.size < length) {
+ throw new IllegalArgumentException("skbuf.size < length");
+ }
+ next = skbuf;
+ skbuf.size = length;
+ }
+ testBuffer();
+ }
- /**
- * Gets a byte in the buffer
- * @param index
- */
- public int get(int index) {
- if (index >= size) {
- if (next != null) {
- return next.get(index - size);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else {
- return data[start + index] & 0xFF;
- }
- }
+ /**
+ * Gets a byte in the buffer
+ *
+ * @param index
+ */
+ public int get(int index) {
+ if (index >= size) {
+ if (next != null) {
+ return next.get(index - size);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else {
+ return data[start + index] & 0xFF;
+ }
+ }
- /**
- * Gets a 16-bit word from the buffer
- * @param index
- */
- public int get16(int index) {
- if (index >= size) {
- // Index is beyond my data
- if (next != null) {
- return next.get16(index - size);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else if (index + 1 < size) {
- // Both bytes are within my data
- final int b0 = data[start + index + 0] & 0xFF;
- final int b1 = data[start + index + 1] & 0xFF;
- return (b0 << 8) | b1;
- } else {
- // First byte is within my data, second is not
- final int b0 = get(index + 0);
- final int b1 = get(index + 1);
- return (b0 << 8) | b1;
- }
- }
+ /**
+ * Gets a 16-bit word from the buffer
+ *
+ * @param index
+ */
+ public int get16(int index) {
+ if (index >= size) {
+ // Index is beyond my data
+ if (next != null) {
+ return next.get16(index - size);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else if (index + 1 < size) {
+ // Both bytes are within my data
+ final int b0 = data[start + index + 0] & 0xFF;
+ final int b1 = data[start + index + 1] & 0xFF;
+ return (b0 << 8) | b1;
+ } else {
+ // First byte is within my data, second is not
+ final int b0 = get(index + 0);
+ final int b1 = get(index + 1);
+ return (b0 << 8) | b1;
+ }
+ }
- /**
- * Gets a 32-bit word from the buffer
- * @param index
- */
- public int get32(int index) {
- if (index >= size) {
- // Index is beyond my data
- if (next != null) {
- return next.get32(index - size);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else if (index + 3 < size) {
- // Both bytes are within my data
- final int b0 = data[start + index + 0] & 0xFF;
- final int b1 = data[start + index + 1] & 0xFF;
- final int b2 = data[start + index + 2] & 0xFF;
- final int b3 = data[start + index + 3] & 0xFF;
- return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
- } else {
- // First byte is within my data, second is not
- final int b0 = get(index + 0);
- final int b1 = get(index + 1);
- final int b2 = get(index + 1);
- final int b3 = get(index + 1);
- return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
- }
- }
+ /**
+ * Gets a 32-bit word from the buffer
+ *
+ * @param index
+ */
+ public int get32(int index) {
+ if (index >= size) {
+ // Index is beyond my data
+ if (next != null) {
+ return next.get32(index - size);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else if (index + 3 < size) {
+ // Both bytes are within my data
+ final int b0 = data[start + index + 0] & 0xFF;
+ final int b1 = data[start + index + 1] & 0xFF;
+ final int b2 = data[start + index + 2] & 0xFF;
+ final int b3 = data[start + index + 3] & 0xFF;
+ return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
+ } else {
+ // First byte is within my data, second is not
+ final int b0 = get(index + 0);
+ final int b1 = get(index + 1);
+ final int b2 = get(index + 1);
+ final int b3 = get(index + 1);
+ return (b0 << 24) | (b1 << 16) | (b2 << 8) | b3;
+ }
+ }
- /**
- * Sets a byte in the buffer
- * @param index
- */
- public void set(int index, int value) {
- if (index >= size) {
- if (next != null) {
- next.set(index - size, value);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else {
- data[start + index] = (byte) value;
- }
- }
+ /**
+ * Sets a byte in the buffer
+ *
+ * @param index
+ */
+ public void set(int index, int value) {
+ if (index >= size) {
+ if (next != null) {
+ next.set(index - size, value);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else {
+ data[start + index] = (byte) value;
+ }
+ }
- /**
- * Sets a 16-bit word in the buffer
- * @param index
- */
- public void set16(int index, int value) {
- if (index >= size) {
- // Index is beyond my data
- if (next != null) {
- next.set16(index - size, value);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else if (index + 1 < size) {
- // Both bytes are within my data
- data[start + index + 0] = (byte) ((value >> 8) & 0xFF);
- data[start + index + 1] = (byte) (value & 0xFF);
- } else {
- // First byte is within my data, second is not
- set(index + 0, ((value >> 8) & 0xFF));
- set(index + 1, (value & 0xFF));
- }
- }
+ /**
+ * Sets a 16-bit word in the buffer
+ *
+ * @param index
+ */
+ public void set16(int index, int value) {
+ if (index >= size) {
+ // Index is beyond my data
+ if (next != null) {
+ next.set16(index - size, value);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else if (index + 1 < size) {
+ // Both bytes are within my data
+ data[start + index + 0] = (byte) ((value >> 8) & 0xFF);
+ data[start + index + 1] = (byte) (value & 0xFF);
+ } else {
+ // First byte is within my data, second is not
+ set(index + 0, ((value >> 8) & 0xFF));
+ set(index + 1, (value & 0xFF));
+ }
+ }
- /**
- * Sets a 32-bit word in the buffer
- * @param index
- */
- public void set32(int index, int value) {
- if (index >= size) {
- // Index is beyond my data
- if (next != null) {
- next.set32(index - size, value);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else if (index + 3 < size) {
- // All bytes are within my data
- data[start + index + 0] = (byte) ((value >> 24) & 0xFF);
- data[start + index + 1] = (byte) ((value >> 16) & 0xFF);
- data[start + index + 2] = (byte) ((value >> 8) & 0xFF);
- data[start + index + 3] = (byte) (value & 0xFF);
- } else {
- // First byte is within my data, last is not
- set(index + 0, ((value >> 24) & 0xFF));
- set(index + 1, ((value >> 16) & 0xFF));
- set(index + 2, ((value >> 8) & 0xFF));
- set(index + 3, (value & 0xFF));
- }
- }
+ /**
+ * Sets a 32-bit word in the buffer
+ *
+ * @param index
+ */
+ public void set32(int index, int value) {
+ if (index >= size) {
+ // Index is beyond my data
+ if (next != null) {
+ next.set32(index - size, value);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else if (index + 3 < size) {
+ // All bytes are within my data
+ data[start + index + 0] = (byte) ((value >> 24) & 0xFF);
+ data[start + index + 1] = (byte) ((value >> 16) & 0xFF);
+ data[start + index + 2] = (byte) ((value >> 8) & 0xFF);
+ data[start + index + 3] = (byte) (value & 0xFF);
+ } else {
+ // First byte is within my data, last is not
+ set(index + 0, ((value >> 24) & 0xFF));
+ set(index + 1, ((value >> 16) & 0xFF));
+ set(index + 2, ((value >> 8) & 0xFF));
+ set(index + 3, (value & 0xFF));
+ }
+ }
- /**
- * Sets a byte-array in the buffer
- * @param index
- */
- public void set(int index, byte[] src, int srcOffset, int length) {
- if (index >= size) {
- // Index is beyond my data
- if (next != null) {
- next.set(index - size, src, srcOffset, length);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else if (index + length <= size) {
- // All bytes are within my data
- System.arraycopy(src, srcOffset, data, start + index, length);
- } else {
- // First byte is within my data, last is not
- if (next != null) {
- final int myLength = size - index;
- System.arraycopy(src, srcOffset, data, start + index, myLength);
- next.set(index - myLength, src, srcOffset + myLength, length - myLength);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- }
- }
+ /**
+ * Sets a byte-array in the buffer
+ *
+ * @param index
+ */
+ public void set(int index, byte[] src, int srcOffset, int length) {
+ if (index >= size) {
+ // Index is beyond my data
+ if (next != null) {
+ next.set(index - size, src, srcOffset, length);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else if (index + length <= size) {
+ // All bytes are within my data
+ System.arraycopy(src, srcOffset, data, start + index, length);
+ } else {
+ // First byte is within my data, last is not
+ if (next != null) {
+ final int myLength = size - index;
+ System.arraycopy(src, srcOffset, data, start + index, myLength);
+ next.set(index - myLength, src, srcOffset + myLength, length - myLength);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ }
+ }
- /**
- * Gets a byte-array in the buffer
- * @param index
- */
- public void get(byte[] dst, int dstOffset, int index, int length) {
- try {
- if (index >= size) {
- // Index is beyond my data
- if (next != null) {
- next.get(dst, dstOffset, index - size, length);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- } else if (index + length <= size) {
- // All bytes are within my data
- System.arraycopy(data, start + index, dst, dstOffset, length);
- } else {
- // First byte is within my data, last is not
- if (next != null) {
- final int myLength = size - index;
- System.arraycopy(data, start + index, dst, dstOffset, myLength);
- next.get(dst, dstOffset + myLength, Math.max(0, index - myLength), length - myLength);
- } else {
- throw new IndexOutOfBoundsException("at index " + index);
- }
- }
- } catch (IndexOutOfBoundsException ex) {
- log.debug("get(dst, " + dstOffset + ", " + index + ", " + length + ") start=" + start + ", size=" + size);
- throw new IndexOutOfBoundsException(ex.getMessage());
- }
- }
+ /**
+ * Gets a byte-array in the buffer
+ *
+ * @param index
+ */
+ public void get(byte[] dst, int dstOffset, int index, int length) {
+ try {
+ if (index >= size) {
+ // Index is beyond my data
+ if (next != null) {
+ next.get(dst, dstOffset, index - size, length);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ } else if (index + length <= size) {
+ // All bytes are within my data
+ System.arraycopy(data, start + index, dst, dstOffset, length);
+ } else {
+ // First byte is within my data, last is not
+ if (next != null) {
+ final int myLength = size - index;
+ System.arraycopy(data, start + index, dst, dstOffset, myLength);
+ next.get(dst, dstOffset + myLength, Math.max(0, index - myLength), length -
+ myLength);
+ } else {
+ throw new IndexOutOfBoundsException("at index " + index);
+ }
+ }
+ } catch (IndexOutOfBoundsException ex) {
+ log.debug("get(dst, " + dstOffset + ", " + index + ", " + length + ") start=" + start +
+ ", size=" + size);
+ throw new IndexOutOfBoundsException(ex.getMessage());
+ }
+ }
- /**
- * Gets the contents of this buffer as a single bytearray.
- * Please note that on concatenated buffers, this can be an expensive
- * function!
- * @return The contents of this buffer
- */
- public byte[] toByteArray() {
- final byte[] result = new byte[getSize()];
- int ofs = 0;
- SocketBuffer skbuf = this;
- do {
- System.arraycopy(skbuf.data, skbuf.start, result, ofs, skbuf.size);
- ofs += skbuf.size;
- skbuf = skbuf.next;
- } while (skbuf != null);
- return result;
- }
+ /**
+ * Gets the contents of this buffer as a single bytearray. Please note that
+ * on concatenated buffers, this can be an expensive function!
+ *
+ * @return The contents of this buffer
+ */
+ public byte[] toByteArray() {
+ final byte[] result = new byte[getSize()];
+ int ofs = 0;
+ SocketBuffer skbuf = this;
+ do {
+ System.arraycopy(skbuf.data, skbuf.start, result, ofs, skbuf.size);
+ ofs += skbuf.size;
+ skbuf = skbuf.next;
+ } while (skbuf != null);
+ return result;
+ }
- /**
- * Gets the used number of bytes in the buffer (and any appended buffers)
- */
- public int getSize() {
- if (next != null) {
- return size + next.getSize();
- } else {
- return size;
- }
- }
+ /**
+ * Gets the used number of bytes in the buffer (and any appended buffers)
+ */
+ public int getSize() {
+ if (next != null) {
+ return size + next.getSize();
+ } else {
+ return size;
+ }
+ }
- /**
- * Set the new buffer size
- * @param newSize
- */
- private void setSize(int newSize) {
- if (data == null) {
- if (newSize > 0) {
- // There is no buffer, create one
- data = new byte[alignSize(Math.max(newSize, INITIAL_SIZE))];
- size = newSize;
- }
- } else if (data.length < start + newSize) {
- // Enlarge the buffer
- final byte[] newData = new byte[alignSize(start + newSize)];
- System.arraycopy(data, start, newData, start, size);
- this.data = newData;
- this.size = newSize;
- } else {
- // The buffer is large enough, update size
- this.size = newSize;
- }
- testBuffer();
- }
+ /**
+ * Set the new buffer size
+ * @param newSize
+ */
+ private void setSize(int newSize) {
+ if (data == null) {
+ if (newSize > 0) {
+ // There is no buffer, create one
+ data = new byte[alignSize(Math.max(newSize, INITIAL_SIZE))];
+ size = newSize;
+ }
+ } else if (data.length < start + newSize) {
+ // Enlarge the buffer
+ final byte[] newData = new byte[alignSize(start + newSize)];
+ System.arraycopy(data, start, newData, start, size);
+ this.data = newData;
+ this.size = newSize;
+ } else {
+ // The buffer is large enough, update size
+ this.size = newSize;
+ }
+ testBuffer();
+ }
- private final int alignSize(int size) {
- return (size + (INITIAL_SIZE - 1)) & ~(INITIAL_SIZE - 1);
- }
+ private final int alignSize(int size) {
+ return (size + (INITIAL_SIZE - 1)) & ~(INITIAL_SIZE - 1);
+ }
- /**
- * Test the parameters of this buffer for illegal combinations.
- */
- private final void testBuffer() {
- if (data == null) {
- if (size != 0) {
- throw new RuntimeException("size(" + size + ") must be 0 when data is null");
- }
- if (start != 0) {
- throw new RuntimeException("start(" + start + ") must be 0 when data is null");
- }
- } else {
- if (size < 0) {
- throw new RuntimeException("size(" + size + ") must be >= 0");
- }
- if (start < 0) {
- throw new RuntimeException("start(" + start + ") must be >= 0");
- }
- if (start + size > data.length) {
- throw new RuntimeException("start(" + start + ")+size(" + size + ") must be <= data.length(" + data.length + ")");
- }
- }
- }
+ /**
+ * Test the parameters of this buffer for illegal combinations.
+ */
+ private final void testBuffer() {
+ if (data == null) {
+ if (size != 0) {
+ throw new RuntimeException("size(" + size + ") must be 0 when data is null");
+ }
+ if (start != 0) {
+ thr...
[truncated message content] |