[freenet-dev] [freenet-cvs] r15875 - in trunk/freenet/src/freenet: clients/http support/api

Matthew Toseland toad at amphibian.dyndns.org
Tue Nov 20 17:05:10 UTC 2007


It should be possible to distinguish between "it existed but had 0 length" 
and "it existed but was too long" ... we should return null, or throw an 
exception, or something .. ?

On Tuesday 20 November 2007 16:33, you wrote:
> Author: bombe
> Date: 2007-11-20 16:33:17 +0000 (Tue, 20 Nov 2007)
> New Revision: 15875
> 
> Modified:
>    trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java
>    trunk/freenet/src/freenet/support/api/HTTPRequest.java
> Log:
> add getPartAsBytes(String, int)
> re-implement getPartAsString(String, int) and use UTF-8 as encoding
> 
> Modified: trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java
> ===================================================================
> --- trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java	2007-11-20 
15:43:25 UTC (rev 15874)
> +++ trunk/freenet/src/freenet/clients/http/HTTPRequestImpl.java	2007-11-20 
16:33:17 UTC (rev 15875)
> @@ -538,15 +538,24 @@
>  
>  		return this.parts.containsKey(name);
>  	}
> -	
> +
> +	public String getPartAsString(String name, int maxlength) {
> +		try {
> +			return new String(getPartAsBytes(name, maxlength), "UTF-8");
> +		} catch (UnsupportedEncodingException e) {
> +			/* UTF-8 is always supported. */
> +		}
> +		return null;
> +	}
> +
>  	/* (non-Javadoc)
>  	 * @see freenet.clients.http.HTTPRequest#getPartAsString(java.lang.String, 
int)
>  	 */
> -	public String getPartAsString(String name, int maxlength) {
> +	public byte[] getPartAsBytes(String name, int maxlength) {
>  		Bucket part = (Bucket)this.parts.get(name);
> -		if(part == null) return "";
> +		if(part == null) return new byte[0];
>  		
> -		if (part.size() > maxlength) return "";
> +		if (part.size() > maxlength) return new byte[0];
>  		
>  		InputStream is = null;
>  		DataInputStream dis = null;
> @@ -555,7 +564,7 @@
>  			dis = new DataInputStream(is);
>  			byte[] buf = new byte[is.available()];
>  			dis.readFully(buf);
> -			return new String(buf);
> +			return buf;
>  		} catch (IOException ioe) {
>  	         Logger.error(this, "Caught IOE:" + ioe.getMessage());
>  		} finally {
> @@ -567,7 +576,7 @@
>  			} catch (IOException ioe) {}
>  		}
>  		
> -		return "";
> +		return new byte[0];
>  	}
>  	
>  	/* (non-Javadoc)
> 
> Modified: trunk/freenet/src/freenet/support/api/HTTPRequest.java
> ===================================================================
> --- trunk/freenet/src/freenet/support/api/HTTPRequest.java	2007-11-20 
15:43:25 UTC (rev 15874)
> +++ trunk/freenet/src/freenet/support/api/HTTPRequest.java	2007-11-20 
16:33:17 UTC (rev 15875)
> @@ -121,6 +121,8 @@
>  	 */
>  	public String getPartAsString(String name, int maxlength);
>  
> +	public byte[] getPartAsBytes(String name, int maxlength);
> +
>  	public void freeParts();
>  
>  	public long getLongParam(String name, long defaultValue);
> 
> _______________________________________________
> cvs mailing list
> cvs at freenetproject.org
> http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs
> 
> 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://emu.freenetproject.org/pipermail/devl/attachments/20071120/44d3386e/attachment.pgp 


More information about the Devl mailing list