93 lines
2.1 KiB
Java
93 lines
2.1 KiB
Java
package org.cl0zzzy.rtmp;
|
|
|
|
public class AMFObject {
|
|
|
|
public static final byte AMF_NUMBER = 0x00;
|
|
public static final byte AMF_BOOLEAN = 0x01;
|
|
public static final byte AMF_STRING = 0x02;
|
|
public static final byte AMF_OBJECT_START = 0x03;
|
|
public static final byte AMF_ECMA_ARRAY_START = 0x08;
|
|
public static final byte AMF_OBJECT_END = 0x09;
|
|
public static final byte AMF_NULL = 0x05;
|
|
public static final byte AMF_DATE = (byte) 0x0b;
|
|
|
|
private byte type;
|
|
private Object body;
|
|
|
|
public AMFObject( byte type, Object body ) {
|
|
this.type = type;
|
|
this.body = body;
|
|
}
|
|
|
|
|
|
public AMFObjectArray getObjectArray() {
|
|
return (AMFObjectArray) this.body;
|
|
}
|
|
|
|
public AMFEcmaArray getECMArray() {
|
|
return (AMFEcmaArray) this.body;
|
|
}
|
|
|
|
public int getInt() {
|
|
return (int) (this.getDouble());
|
|
}
|
|
|
|
public double getDouble() {
|
|
if( this.body != null ) {
|
|
return Double.parseDouble( String.valueOf( this.body ) );
|
|
} else {
|
|
return 0.0;
|
|
}
|
|
}
|
|
|
|
public String getString() {
|
|
if( this.getType() == AMFObject.AMF_OBJECT_START ) {
|
|
String str = "Object";
|
|
AMFObjectArray obj = this.getObjectArray();
|
|
for( int i = 0; i < obj.getLength(); i++ ) {
|
|
str = str + "\nObject -> " + obj.getKeyAt(i) + "=" + obj.getValueAt(i).getString();
|
|
}
|
|
return str;
|
|
} else if( this.getType() == AMFObject.AMF_ECMA_ARRAY_START ) {
|
|
String str = "Array";
|
|
AMFEcmaArray obj = this.getECMArray();
|
|
for( int i = 0; i < obj.getLength(); i++ ) {
|
|
str = str + "\nArray -> " + i + "=" + obj.getValueAt(i).getString();
|
|
}
|
|
return str;
|
|
} else {
|
|
return String.valueOf( this.body );
|
|
}
|
|
}
|
|
|
|
public Object get() {
|
|
return this.body;
|
|
}
|
|
|
|
public byte getType() {
|
|
return this.type;
|
|
}
|
|
|
|
public Boolean isNull() {
|
|
return ( this.body == null );
|
|
}
|
|
|
|
public Boolean getBoolean() {
|
|
return Boolean.valueOf( this.getString() );
|
|
}
|
|
|
|
public String toString() {
|
|
return this.getString();
|
|
}
|
|
|
|
public String toString( boolean i ) {
|
|
if( this.getType() == AMFObject.AMF_OBJECT_START ) {
|
|
return "Object";
|
|
} else if( this.getType() == AMFObject.AMF_ECMA_ARRAY_START ) {
|
|
return "Array";
|
|
} else {
|
|
return String.valueOf( this.body );
|
|
}
|
|
}
|
|
}
|