@Override public byte[] bEncode( Map map ) throws IOException { return( BEncoder.encode( map )); }
protected ByteBuffer getMessage() throws IOException { Map map = new HashMap(); map.put( "check", check ); byte[] map_bytes = BEncoder.encode( map ); ByteBuffer msg = ByteBuffer.allocate( 4 + map_bytes.length ); msg.putInt( map_bytes.length ); msg.put( map_bytes ); msg.flip(); return( msg ); }
public byte[] getBencodedData() { if (this.bencoded_data == null) { try {this.bencoded_data = BEncoder.encode(this.data_dict);} catch (java.io.IOException ioe) { this.bencoded_data = new byte[0]; Debug.printStackTrace(ioe); } } return this.bencoded_data; }
@Override public void serialise( DataOutputStream os ) throws IOException { super.serialise(os); byte[] bytes = BEncoder.encode( payload ); os.writeShort( (short)bytes.length ); os.write( bytes ); }
@Override public void serialise( DataOutputStream os ) throws IOException { super.serialise(os); byte[] bytes = BEncoder.encode( payload ); os.writeShort( (short)bytes.length ); os.write( bytes ); }
@Override public void serialise( DataOutputStream os ) throws IOException { super.serialise(os); byte[] bytes = BEncoder.encode( payload ); os.writeShort( (short)bytes.length ); os.write( bytes ); }
@Override public byte[] exportToBytes() throws IOException { return( BEncoder.encode( exportToMap())); }
@Override public void serialise( DataOutputStream os ) throws IOException { super.serialise(os); byte[] bytes = BEncoder.encode( payload ); os.writeShort( (short)bytes.length ); os.write( bytes ); }
@Override public PooledByteBuffer allocatePooledByteBuffer( Map map ) throws IOException { return( new PooledByteBufferImpl( BEncoder.encode( map ))); }
private Map sendRequest( Map request ) throws IOException { request.put( "ver", new Long(1) );//request version request.put( "locale", MessageText.getCurrentLocale().toString()); String speedTestServiceName = System.getProperty( "speedtest.service.ip.address", Constants.SPEED_TEST_SERVER ); URL urlRequestTest = new URL("http://"+speedTestServiceName+":60000/scheduletest?request=" + URLEncoder.encode( new String(BEncoder.encode(request),"ISO-8859-1"),"ISO-8859-1")); return( getBEncodedMapFromRequest( urlRequestTest )); } /**
protected static void embedEngines( Map map, Engine engine ) { Map engines = new HashMap(); map.put( "engines", engines ); Map engine_map = new HashMap(); try{ String engine_str = new String( Base64.encode( BEncoder.encode( engine.exportToBencodedMap())), "UTF-8" ); engine_map.put( "content", engine_str ); engines.put( String.valueOf( engine.getId()), engine_map ); }catch( Throwable e ){ Debug.out( e ); } }
@Override public byte[] writeToBEncodedData() throws TorrentException { try{ Map map = torrent.serialiseToMap(); return( BEncoder.encode( map )); }catch( Throwable e ){ throw( new TorrentException( "Torrent::writeToBEncodedData: fails", e )); } }
protected byte[] signAndInsert( Map plain_stuff, String reason ) throws BuddyPluginException { try{ byte[] data = BEncoder.encode( plain_stuff ); byte[] signature = ecc_handler.sign( data, reason ); byte[] signed_payload = new byte[ 1 + signature.length + data.length ]; signed_payload[0] = (byte)signature.length; System.arraycopy( signature, 0, signed_payload, 1, signature.length ); System.arraycopy( data, 0, signed_payload, 1 + signature.length, data.length ); return( signed_payload ); }catch( Throwable e ){ rethrow( "Signing failed", e ); return( null ); } }
private String getHTTPGetString( Map content, boolean for_proxy, boolean v6 ) { String host = getHost( v6, HTTP_SERVER_ADDRESS_V6, HTTP_SERVER_ADDRESS_V4 ); String get_str = "GET " + (for_proxy?("http://" + (v6?UrlUtils.convertIPV6Host( host ):host ) + ":" + HTTP_SERVER_PORT ):"") +"/version?"; try{ get_str += URLEncoder.encode( new String( BEncoder.encode( content ), "ISO-8859-1" ), "ISO-8859-1" ); }catch( Throwable e ){ } get_str +=" HTTP/1.1" + "\015\012" + "\015\012"; return( get_str ); }
@Override public byte[] getTorrentInfoDict( PEPeer peer ) { try{ byte[] data = md_info_dict_ref.get(); if ( data == null ){ TOTorrent torrent = PluginCoreUtils.unwrap( lws.getTorrent()); data = BEncoder.encode((Map)torrent.serialiseToMap().get( "info" )); md_info_dict_ref = new WeakReference<>(data); } return( data ); }catch( Throwable e ){ return( null ); } }
protected static void serialiseAltContact( DataOutputStream os, DHTTransportAlternativeContact contact ) throws IOException, DHTTransportException { os.write((byte)contact.getNetworkType()); os.write((byte)contact.getVersion()); os.writeShort( contact.getAge()); byte[] encoded = BEncoder.encode( contact.getProperties()); serialiseByteArray( os, encoded, 65535 ); }
protected byte[] serialiseToByteArray() throws TOTorrentException { if ( created ){ TorrentUtils.addCreatedTorrent( this ); } Map root = serialiseToMap(); try{ return( BEncoder.encode( root )); }catch( IOException e ){ throw( new TOTorrentException( "Failed to serialise torrent: " + Debug.getNestedExceptionMessage(e), TOTorrentException.RT_WRITE_FAILS )); } }
@Override public Message deserialize( DirectByteBuffer data, byte version ) throws MessageException { int pos = data.position( DirectByteBuffer.SS_MSG ); byte[] dict_bytes = new byte[ Math.min( 128, data.remaining( DirectByteBuffer.SS_MSG )) ]; data.get( DirectByteBuffer.SS_MSG, dict_bytes ); try{ Map root = BDecoder.decode( dict_bytes ); data.position( DirectByteBuffer.SS_MSG, pos + BEncoder.encode( root ).length ); return( new UTMetaData( root, data, version )); }catch( Throwable e ){ e.printStackTrace(); throw( new MessageException( "decode failed", e )); } }
protected void setHashFromInfo( Map info ) throws TOTorrentException { try{ if ( torrent_hash_override == null ){ SHA1Hasher s = new SHA1Hasher(); torrent_hash = s.calculateHash(BEncoder.encode(info)); }else{ torrent_hash = torrent_hash_override; } torrent_hash_wrapper = new HashWrapper( torrent_hash ); }catch( Throwable e ){ throw( new TOTorrentException( "Failed to calculate hash: " + Debug.getNestedExceptionMessage(e), TOTorrentException.RT_HASH_FAILS )); } }
@Override public DistributedDatabaseValue read( DistributedDatabaseContact contact, DistributedDatabaseTransferType type, DistributedDatabaseKey ddb_key ) throws DistributedDatabaseException { Object o_key = ddb_key.getKey(); try{ byte[] key = (byte[])o_key; // TODO bloom Map<String,Object> request = BDecoder.decode( key ); Map<String,Object> result = receiveRemoteRequest( contact, request ); return( ddb.createValue( BEncoder.encode( result ))); }catch( Throwable e ){ Debug.out( e ); return( null ); } }