{
byte[] res;
if ( obj == null ){
throw( new DistributedDatabaseException( "null not supported" ));
}else if ( obj instanceof byte[] ){
res = (byte[])obj;
}else if ( obj instanceof String ){
try{
res = ((String)obj).getBytes("UTF-8");
}catch( UnsupportedEncodingException e ){
throw( new DistributedDatabaseException( "charset error", e ));
}
}else if ( obj instanceof Byte ||
obj instanceof Short ||
obj instanceof Integer ||
obj instanceof Long ||
obj instanceof Float ||
obj instanceof Double ||
obj instanceof Boolean ){
throw( new DistributedDatabaseException( "not supported yet!" ));
}else{
try{
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream( baos );
oos.writeObject( obj );
oos.close();
res = baos.toByteArray();
}catch( Throwable e ){
throw( new DistributedDatabaseException( "encoding fails", e ));
}
}
return( res );
}