net.jradius.packet
Class Format

java.lang.Object
  extended by net.jradius.packet.Format
Direct Known Subclasses:
DHCPFormat, DiameterFormat, RadiusFormat, TLVFormat

public abstract class Format
extends Object

Author:
David Bird

Nested Class Summary
protected  class Format.AttributeParseContext
           
 
Constructor Summary
Format()
           
 
Method Summary
static short getUnsignedByte(ByteBuffer bb)
           
static short getUnsignedByte(ByteBuffer bb, int position)
           
static long getUnsignedInt(ByteBuffer bb)
           
static long getUnsignedInt(ByteBuffer bb, int position)
           
static int getUnsignedShort(ByteBuffer bb)
           
static int getUnsignedShort(ByteBuffer bb, int position)
           
abstract  void packAttribute(ByteBuffer buffer, RadiusAttribute a)
           
 void packAttributeList(AttributeList attrs, ByteBuffer buffer, boolean onWire)
          Packs an AttributeList into a byte array
 void packAttributes(ByteBuffer buffer, List<VSAttribute> list)
           
static void putUnsignedByte(ByteBuffer bb, int value)
           
static void putUnsignedByte(ByteBuffer bb, int position, int value)
           
static void putUnsignedInt(ByteBuffer bb, int position, long value)
           
static void putUnsignedInt(ByteBuffer bb, long value)
           
static void putUnsignedShort(ByteBuffer bb, int value)
           
static void putUnsignedShort(ByteBuffer bb, int position, int value)
           
static int readUnsignedByte(InputStream in)
           
static long readUnsignedInt(InputStream in)
           
static int readUnsignedShort(InputStream in)
           
abstract  void unpackAttributeHeader(ByteBuffer buffer, Format.AttributeParseContext ctx)
           
 void unpackAttributes(AttributeList attrs, ByteBuffer buffer, int length)
          Unpacks RadiusAttributes from a byte array into an AttributeList
static void writeUnsignedByte(OutputStream out, int b)
           
static void writeUnsignedInt(OutputStream out, long i)
           
static void writeUnsignedShort(OutputStream out, int s)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Format

public Format()
Method Detail

packAttribute

public abstract void packAttribute(ByteBuffer buffer,
                                   RadiusAttribute a)

packAttributes

public void packAttributes(ByteBuffer buffer,
                           List<VSAttribute> list)

unpackAttributeHeader

public abstract void unpackAttributeHeader(ByteBuffer buffer,
                                           Format.AttributeParseContext ctx)
                                    throws IOException
Throws:
IOException

packAttributeList

public void packAttributeList(AttributeList attrs,
                              ByteBuffer buffer,
                              boolean onWire)
Packs an AttributeList into a byte array

Parameters:
attrs - The AttributeList to pack

unpackAttributes

public void unpackAttributes(AttributeList attrs,
                             ByteBuffer buffer,
                             int length)
Unpacks RadiusAttributes from a byte array into an AttributeList

Parameters:
attrs - The AttributeList to put unpacked attributes
bytes - The bytes to be unpacked
bLength - The length of the bytes to be unpacked public void unpackAttributes(AttributeList attrs, byte[] bytes, int bOffset, int bLength) { InputStream attributeInput = new ByteArrayInputStream(bytes, bOffset, bLength); try { for (int pos = 0; pos < bLength; ) { AttributeParseContext ctx = new AttributeParseContext(); pos += unpackAttributeHeader(attributeInput, ctx); RadiusAttribute attribute = null; ctx.attributeValue = new byte[(int)(ctx.attributeLength - ctx.headerLength)]; attributeInput.read(ctx.attributeValue, 0, (int)(ctx.attributeLength - ctx.headerLength)); attribute = AttributeFactory.newAttribute(ctx.vendorNumber, ctx.attributeType, ctx.attributeValue, (int) ctx.attributeOp); if (attribute == null) { RadiusLog.warn("Unknown attribute with type = " + ctx.attributeType); } else { attrs._add(attribute, false); } if (ctx.padding > 0) { pos += ctx.padding; while (ctx.padding-- > 0) { readUnsignedByte(attributeInput); } } pos += ctx.attributeLength; } attributeInput.close(); } catch (IOException e) { RadiusLog.warn(e.getMessage(), e); } }

readUnsignedInt

public static long readUnsignedInt(InputStream in)
                            throws IOException
Throws:
IOException

readUnsignedShort

public static int readUnsignedShort(InputStream in)
                             throws IOException
Throws:
IOException

readUnsignedByte

public static int readUnsignedByte(InputStream in)
                            throws IOException
Throws:
IOException

writeUnsignedByte

public static void writeUnsignedByte(OutputStream out,
                                     int b)
                              throws IOException
Throws:
IOException

writeUnsignedShort

public static void writeUnsignedShort(OutputStream out,
                                      int s)
                               throws IOException
Throws:
IOException

writeUnsignedInt

public static void writeUnsignedInt(OutputStream out,
                                    long i)
                             throws IOException
Throws:
IOException

getUnsignedByte

public static short getUnsignedByte(ByteBuffer bb)

putUnsignedByte

public static void putUnsignedByte(ByteBuffer bb,
                                   int value)

getUnsignedByte

public static short getUnsignedByte(ByteBuffer bb,
                                    int position)

putUnsignedByte

public static void putUnsignedByte(ByteBuffer bb,
                                   int position,
                                   int value)

getUnsignedShort

public static int getUnsignedShort(ByteBuffer bb)

putUnsignedShort

public static void putUnsignedShort(ByteBuffer bb,
                                    int value)

getUnsignedShort

public static int getUnsignedShort(ByteBuffer bb,
                                   int position)

putUnsignedShort

public static void putUnsignedShort(ByteBuffer bb,
                                    int position,
                                    int value)

getUnsignedInt

public static long getUnsignedInt(ByteBuffer bb)

putUnsignedInt

public static void putUnsignedInt(ByteBuffer bb,
                                  long value)

getUnsignedInt

public static long getUnsignedInt(ByteBuffer bb,
                                  int position)

putUnsignedInt

public static void putUnsignedInt(ByteBuffer bb,
                                  int position,
                                  long value)


Copyright © 2011 Coova Technologies, LLC, All Rights Reserved.