You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2009/05/22 20:52:13 UTC

svn commit: r777655 - /camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java

Author: davsclaus
Date: Fri May 22 18:52:13 2009
New Revision: 777655

URL: http://svn.apache.org/viewvc?rev=777655&view=rev
Log:
polished code

Modified:
    camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java

Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java?rev=777655&r1=777654&r2=777655&view=diff
==============================================================================
--- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java (original)
+++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java Fri May 22 18:52:13 2009
@@ -29,12 +29,8 @@
 
 public class GzipDataFormat implements DataFormat {
 
-    public void marshal(Exchange exchange, Object graph, OutputStream stream)
-        throws Exception {
-        InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, graph);
-        if (is == null) {
-            throw new IllegalArgumentException("Cannot get the inputstream for GzipDataFormat mashalling");
-        }
+    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
+        InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, graph);
 
         GZIPOutputStream zipOutput = new GZIPOutputStream(stream);
         try {
@@ -45,8 +41,7 @@
         
     }
 
-    public Object unmarshal(Exchange exchange, InputStream stream)
-        throws Exception {
+    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
         InputStream is = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
         GZIPInputStream unzipInput = new GZIPInputStream(is);
         



Re: svn commit: r777655 - /camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java

Posted by Willem Jiang <wi...@gmail.com>.
Got it, thanks for the explanation.

Willem

Claus Ibsen wrote:
> On Sat, May 23, 2009 at 4:12 AM, Willem Jiang <wi...@gmail.com> wrote:
>> Hi Claus,
>>
>> I don't know why did you remove the checking codes of 'is' (the instance
>> of InputStream). Do I miss something ?
> Hi
> 
> We have the mandatoryConvertTo method that will throw a exception if
> Camel cannot converter to the given type.
> People should use this method instead of doing their own == null check.
> 
> So I changed from convertTo to the mandatoryConvertTo method.
> And removed the if == null check.
> 
> 
>> Thanks,
>>
>> Willem
>> davsclaus@apache.org wrote:
>>> Author: davsclaus
>>> Date: Fri May 22 18:52:13 2009
>>> New Revision: 777655
>>>
>>> URL: http://svn.apache.org/viewvc?rev=777655&view=rev
>>> Log:
>>> polished code
>>>
>>> Modified:
>>>     camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
>>>
>>> Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
>>> URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java?rev=777655&r1=777654&r2=777655&view=diff
>>> ==============================================================================
>>> --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java (original)
>>> +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java Fri May 22 18:52:13 2009
>>> @@ -29,12 +29,8 @@
>>>
>>>  public class GzipDataFormat implements DataFormat {
>>>
>>> -    public void marshal(Exchange exchange, Object graph, OutputStream stream)
>>> -        throws Exception {
>>> -        InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, graph);
>>> -        if (is == null) {
>>> -            throw new IllegalArgumentException("Cannot get the inputstream for GzipDataFormat mashalling");
>>> -        }
>>> +    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
>>> +        InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, graph);
>>>
>>>          GZIPOutputStream zipOutput = new GZIPOutputStream(stream);
>>>          try {
>>> @@ -45,8 +41,7 @@
>>>
>>>      }
>>>
>>> -    public Object unmarshal(Exchange exchange, InputStream stream)
>>> -        throws Exception {
>>> +    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
>>>          InputStream is = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
>>>          GZIPInputStream unzipInput = new GZIPInputStream(is);
>>>
>>>
>>>
>>>
>>
> 
> 
> 


Re: svn commit: r777655 - /camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java

Posted by Claus Ibsen <cl...@gmail.com>.
On Sat, May 23, 2009 at 4:12 AM, Willem Jiang <wi...@gmail.com> wrote:
> Hi Claus,
>
> I don't know why did you remove the checking codes of 'is' (the instance
> of InputStream). Do I miss something ?
Hi

We have the mandatoryConvertTo method that will throw a exception if
Camel cannot converter to the given type.
People should use this method instead of doing their own == null check.

So I changed from convertTo to the mandatoryConvertTo method.
And removed the if == null check.


>
> Thanks,
>
> Willem
> davsclaus@apache.org wrote:
>> Author: davsclaus
>> Date: Fri May 22 18:52:13 2009
>> New Revision: 777655
>>
>> URL: http://svn.apache.org/viewvc?rev=777655&view=rev
>> Log:
>> polished code
>>
>> Modified:
>>     camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
>>
>> Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
>> URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java?rev=777655&r1=777654&r2=777655&view=diff
>> ==============================================================================
>> --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java (original)
>> +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java Fri May 22 18:52:13 2009
>> @@ -29,12 +29,8 @@
>>
>>  public class GzipDataFormat implements DataFormat {
>>
>> -    public void marshal(Exchange exchange, Object graph, OutputStream stream)
>> -        throws Exception {
>> -        InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, graph);
>> -        if (is == null) {
>> -            throw new IllegalArgumentException("Cannot get the inputstream for GzipDataFormat mashalling");
>> -        }
>> +    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
>> +        InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, graph);
>>
>>          GZIPOutputStream zipOutput = new GZIPOutputStream(stream);
>>          try {
>> @@ -45,8 +41,7 @@
>>
>>      }
>>
>> -    public Object unmarshal(Exchange exchange, InputStream stream)
>> -        throws Exception {
>> +    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
>>          InputStream is = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
>>          GZIPInputStream unzipInput = new GZIPInputStream(is);
>>
>>
>>
>>
>
>



-- 
Claus Ibsen
Apache Camel Committer

Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: svn commit: r777655 - /camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java

Posted by Willem Jiang <wi...@gmail.com>.
Hi Claus,

I don't know why did you remove the checking codes of 'is' (the instance
of InputStream). Do I miss something ?

Thanks,

Willem
davsclaus@apache.org wrote:
> Author: davsclaus
> Date: Fri May 22 18:52:13 2009
> New Revision: 777655
> 
> URL: http://svn.apache.org/viewvc?rev=777655&view=rev
> Log:
> polished code
> 
> Modified:
>     camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
> 
> Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java
> URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java?rev=777655&r1=777654&r2=777655&view=diff
> ==============================================================================
> --- camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java (original)
> +++ camel/trunk/camel-core/src/main/java/org/apache/camel/impl/GzipDataFormat.java Fri May 22 18:52:13 2009
> @@ -29,12 +29,8 @@
>  
>  public class GzipDataFormat implements DataFormat {
>  
> -    public void marshal(Exchange exchange, Object graph, OutputStream stream)
> -        throws Exception {
> -        InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class, graph);
> -        if (is == null) {
> -            throw new IllegalArgumentException("Cannot get the inputstream for GzipDataFormat mashalling");
> -        }
> +    public void marshal(Exchange exchange, Object graph, OutputStream stream) throws Exception {
> +        InputStream is = exchange.getContext().getTypeConverter().mandatoryConvertTo(InputStream.class, graph);
>  
>          GZIPOutputStream zipOutput = new GZIPOutputStream(stream);
>          try {
> @@ -45,8 +41,7 @@
>          
>      }
>  
> -    public Object unmarshal(Exchange exchange, InputStream stream)
> -        throws Exception {
> +    public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
>          InputStream is = ExchangeHelper.getMandatoryInBody(exchange, InputStream.class);
>          GZIPInputStream unzipInput = new GZIPInputStream(is);
>          
> 
> 
>