How to check that a file is empty

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to check that a file is empty

Bengt Rodehav
I have recently upgraded Camel to version 2.11.0. In my file transfer
services I have used a predicate together with interceptors to avoid
transferring empty files but instead move them into a subfolder called
"skipped". However, this has stopped working. My predicate looks like this:

*Predicate emptyFile =
PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} == 0"));
*

I'm not exactly sure in what version this functionality broke but I'm sure
it worked in version 2.7.1.

Is there a better way to do this in Camel 2.11.0?

/Bengt
Reply | Threaded
Open this post in threaded view
|

Re: How to check that a file is empty

Claus Ibsen-2
See also the readLockMinLength option

On Wed, Aug 14, 2013 at 4:26 PM, Bengt Rodehav <[hidden email]> wrote:

> I have recently upgraded Camel to version 2.11.0. In my file transfer
> services I have used a predicate together with interceptors to avoid
> transferring empty files but instead move them into a subfolder called
> "skipped". However, this has stopped working. My predicate looks like this:
>
> *Predicate emptyFile =
> PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} == 0"));
> *
>
> I'm not exactly sure in what version this functionality broke but I'm sure
> it worked in version 2.7.1.
>
> Is there a better way to do this in Camel 2.11.0?
>
> /Bengt



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: How to check that a file is empty

Bengt Rodehav
Thanks for the tip. It would probably be good enough although I also want
to move the empty files to a dedicated directory to clearly show what took
place.

Do you know f the syntax for checking the file length has changed in Simple
language (or rather File language)? Looking at the documentation I can't
see that I'm doing anything wrong.

/Bengt


2013/8/14 Claus Ibsen <[hidden email]>

> See also the readLockMinLength option
>
> On Wed, Aug 14, 2013 at 4:26 PM, Bengt Rodehav <[hidden email]> wrote:
> > I have recently upgraded Camel to version 2.11.0. In my file transfer
> > services I have used a predicate together with interceptors to avoid
> > transferring empty files but instead move them into a subfolder called
> > "skipped". However, this has stopped working. My predicate looks like
> this:
> >
> > *Predicate emptyFile =
> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
> 0"));
> > *
> >
> > I'm not exactly sure in what version this functionality broke but I'm
> sure
> > it worked in version 2.7.1.
> >
> > Is there a better way to do this in Camel 2.11.0?
> >
> > /Bengt
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: [hidden email]
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>
Reply | Threaded
Open this post in threaded view
|

Re: How to check that a file is empty

Bengt Rodehav
My original code that has been working for 2-3 years looks like this:

*Predicate emptyFile =
PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} == 0"));

interceptFrom().when(emptyFile).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
*

For some reason, when using Camel 2.11.0, the above code causes all files
to be skipped (even the non-empty ones). I have found another way of doing
this that works with Camel 2.11.0. It looks as follows:

*
interceptFrom().when(header("CamelFileLength").isEqualTo(0)).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
*

I'm not sure what is happening. Since I have a workaround I'm OK but it
seems like the behaviour of the SimpleLanguage has changed somehow. Could
be a bug or at least something worth documenting.

Any thoughts?

/Bengt





2013/8/14 Bengt Rodehav <[hidden email]>

> Thanks for the tip. It would probably be good enough although I also want
> to move the empty files to a dedicated directory to clearly show what took
> place.
>
> Do you know f the syntax for checking the file length has changed in
> Simple language (or rather File language)? Looking at the documentation I
> can't see that I'm doing anything wrong.
>
> /Bengt
>
>
> 2013/8/14 Claus Ibsen <[hidden email]>
>
>> See also the readLockMinLength option
>>
>> On Wed, Aug 14, 2013 at 4:26 PM, Bengt Rodehav <[hidden email]> wrote:
>> > I have recently upgraded Camel to version 2.11.0. In my file transfer
>> > services I have used a predicate together with interceptors to avoid
>> > transferring empty files but instead move them into a subfolder called
>> > "skipped". However, this has stopped working. My predicate looks like
>> this:
>> >
>> > *Predicate emptyFile =
>> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
>> 0"));
>> > *
>> >
>> > I'm not exactly sure in what version this functionality broke but I'm
>> sure
>> > it worked in version 2.7.1.
>> >
>> > Is there a better way to do this in Camel 2.11.0?
>> >
>> > /Bengt
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: [hidden email]
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>
>
>
Reply | Threaded
Open this post in threaded view
|

Re: How to check that a file is empty

Claus Ibsen-2
Hi

This is because you use the simple language "wrong" as you create an
expression, and NOT a predicate.

I have logged a ticket to improve on this, so you have static methods
to easily create a predicate
https://issues.apache.org/jira/browse/CAMEL-6639

On Thu, Aug 15, 2013 at 9:49 AM, Bengt Rodehav <[hidden email]> wrote:

> My original code that has been working for 2-3 years looks like this:
>
> *Predicate emptyFile =
> PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} == 0"));
>
> interceptFrom().when(emptyFile).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
> *
>
> For some reason, when using Camel 2.11.0, the above code causes all files
> to be skipped (even the non-empty ones). I have found another way of doing
> this that works with Camel 2.11.0. It looks as follows:
>
> *
> interceptFrom().when(header("CamelFileLength").isEqualTo(0)).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
> *
>
> I'm not sure what is happening. Since I have a workaround I'm OK but it
> seems like the behaviour of the SimpleLanguage has changed somehow. Could
> be a bug or at least something worth documenting.
>
> Any thoughts?
>
> /Bengt
>
>
>
>
>
> 2013/8/14 Bengt Rodehav <[hidden email]>
>
>> Thanks for the tip. It would probably be good enough although I also want
>> to move the empty files to a dedicated directory to clearly show what took
>> place.
>>
>> Do you know f the syntax for checking the file length has changed in
>> Simple language (or rather File language)? Looking at the documentation I
>> can't see that I'm doing anything wrong.
>>
>> /Bengt
>>
>>
>> 2013/8/14 Claus Ibsen <[hidden email]>
>>
>>> See also the readLockMinLength option
>>>
>>> On Wed, Aug 14, 2013 at 4:26 PM, Bengt Rodehav <[hidden email]> wrote:
>>> > I have recently upgraded Camel to version 2.11.0. In my file transfer
>>> > services I have used a predicate together with interceptors to avoid
>>> > transferring empty files but instead move them into a subfolder called
>>> > "skipped". However, this has stopped working. My predicate looks like
>>> this:
>>> >
>>> > *Predicate emptyFile =
>>> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
>>> 0"));
>>> > *
>>> >
>>> > I'm not exactly sure in what version this functionality broke but I'm
>>> sure
>>> > it worked in version 2.7.1.
>>> >
>>> > Is there a better way to do this in Camel 2.11.0?
>>> >
>>> > /Bengt
>>>
>>>
>>>
>>> --
>>> Claus Ibsen
>>> -----------------
>>> Red Hat, Inc.
>>> Email: [hidden email]
>>> Twitter: davsclaus
>>> Blog: http://davsclaus.com
>>> Author of Camel in Action: http://www.manning.com/ibsen
>>>
>>
>>



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: How to check that a file is empty

Bengt Rodehav
Thanks Claus.

I do believe that the "PredicateBuilder.toPredicate" method I use does take
an expression as a parameter and returns a Predicate. Which method should I
have used?

/Bengt




2013/8/15 Claus Ibsen <[hidden email]>

> Hi
>
> This is because you use the simple language "wrong" as you create an
> expression, and NOT a predicate.
>
> I have logged a ticket to improve on this, so you have static methods
> to easily create a predicate
> https://issues.apache.org/jira/browse/CAMEL-6639
>
> On Thu, Aug 15, 2013 at 9:49 AM, Bengt Rodehav <[hidden email]> wrote:
> > My original code that has been working for 2-3 years looks like this:
> >
> > *Predicate emptyFile =
> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
> 0"));
> >
> >
> interceptFrom().when(emptyFile).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
> > *
> >
> > For some reason, when using Camel 2.11.0, the above code causes all files
> > to be skipped (even the non-empty ones). I have found another way of
> doing
> > this that works with Camel 2.11.0. It looks as follows:
> >
> > *
> >
> interceptFrom().when(header("CamelFileLength").isEqualTo(0)).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
> > *
> >
> > I'm not sure what is happening. Since I have a workaround I'm OK but it
> > seems like the behaviour of the SimpleLanguage has changed somehow. Could
> > be a bug or at least something worth documenting.
> >
> > Any thoughts?
> >
> > /Bengt
> >
> >
> >
> >
> >
> > 2013/8/14 Bengt Rodehav <[hidden email]>
> >
> >> Thanks for the tip. It would probably be good enough although I also
> want
> >> to move the empty files to a dedicated directory to clearly show what
> took
> >> place.
> >>
> >> Do you know f the syntax for checking the file length has changed in
> >> Simple language (or rather File language)? Looking at the documentation
> I
> >> can't see that I'm doing anything wrong.
> >>
> >> /Bengt
> >>
> >>
> >> 2013/8/14 Claus Ibsen <[hidden email]>
> >>
> >>> See also the readLockMinLength option
> >>>
> >>> On Wed, Aug 14, 2013 at 4:26 PM, Bengt Rodehav <[hidden email]>
> wrote:
> >>> > I have recently upgraded Camel to version 2.11.0. In my file transfer
> >>> > services I have used a predicate together with interceptors to avoid
> >>> > transferring empty files but instead move them into a subfolder
> called
> >>> > "skipped". However, this has stopped working. My predicate looks like
> >>> this:
> >>> >
> >>> > *Predicate emptyFile =
> >>> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
> >>> 0"));
> >>> > *
> >>> >
> >>> > I'm not exactly sure in what version this functionality broke but I'm
> >>> sure
> >>> > it worked in version 2.7.1.
> >>> >
> >>> > Is there a better way to do this in Camel 2.11.0?
> >>> >
> >>> > /Bengt
> >>>
> >>>
> >>>
> >>> --
> >>> Claus Ibsen
> >>> -----------------
> >>> Red Hat, Inc.
> >>> Email: [hidden email]
> >>> Twitter: davsclaus
> >>> Blog: http://davsclaus.com
> >>> Author of Camel in Action: http://www.manning.com/ibsen
> >>>
> >>
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: [hidden email]
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>
Reply | Threaded
Open this post in threaded view
|

Re: How to check that a file is empty

Claus Ibsen-2
There should be non static methods on simple language to create a predicate.

On Thu, Aug 15, 2013 at 1:43 PM, Bengt Rodehav <[hidden email]> wrote:

> Thanks Claus.
>
> I do believe that the "PredicateBuilder.toPredicate" method I use does take
> an expression as a parameter and returns a Predicate. Which method should I
> have used?
>
> /Bengt
>
>
>
>
> 2013/8/15 Claus Ibsen <[hidden email]>
>
>> Hi
>>
>> This is because you use the simple language "wrong" as you create an
>> expression, and NOT a predicate.
>>
>> I have logged a ticket to improve on this, so you have static methods
>> to easily create a predicate
>> https://issues.apache.org/jira/browse/CAMEL-6639
>>
>> On Thu, Aug 15, 2013 at 9:49 AM, Bengt Rodehav <[hidden email]> wrote:
>> > My original code that has been working for 2-3 years looks like this:
>> >
>> > *Predicate emptyFile =
>> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
>> 0"));
>> >
>> >
>> interceptFrom().when(emptyFile).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
>> > *
>> >
>> > For some reason, when using Camel 2.11.0, the above code causes all files
>> > to be skipped (even the non-empty ones). I have found another way of
>> doing
>> > this that works with Camel 2.11.0. It looks as follows:
>> >
>> > *
>> >
>> interceptFrom().when(header("CamelFileLength").isEqualTo(0)).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
>> > *
>> >
>> > I'm not sure what is happening. Since I have a workaround I'm OK but it
>> > seems like the behaviour of the SimpleLanguage has changed somehow. Could
>> > be a bug or at least something worth documenting.
>> >
>> > Any thoughts?
>> >
>> > /Bengt
>> >
>> >
>> >
>> >
>> >
>> > 2013/8/14 Bengt Rodehav <[hidden email]>
>> >
>> >> Thanks for the tip. It would probably be good enough although I also
>> want
>> >> to move the empty files to a dedicated directory to clearly show what
>> took
>> >> place.
>> >>
>> >> Do you know f the syntax for checking the file length has changed in
>> >> Simple language (or rather File language)? Looking at the documentation
>> I
>> >> can't see that I'm doing anything wrong.
>> >>
>> >> /Bengt
>> >>
>> >>
>> >> 2013/8/14 Claus Ibsen <[hidden email]>
>> >>
>> >>> See also the readLockMinLength option
>> >>>
>> >>> On Wed, Aug 14, 2013 at 4:26 PM, Bengt Rodehav <[hidden email]>
>> wrote:
>> >>> > I have recently upgraded Camel to version 2.11.0. In my file transfer
>> >>> > services I have used a predicate together with interceptors to avoid
>> >>> > transferring empty files but instead move them into a subfolder
>> called
>> >>> > "skipped". However, this has stopped working. My predicate looks like
>> >>> this:
>> >>> >
>> >>> > *Predicate emptyFile =
>> >>> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
>> >>> 0"));
>> >>> > *
>> >>> >
>> >>> > I'm not exactly sure in what version this functionality broke but I'm
>> >>> sure
>> >>> > it worked in version 2.7.1.
>> >>> >
>> >>> > Is there a better way to do this in Camel 2.11.0?
>> >>> >
>> >>> > /Bengt
>> >>>
>> >>>
>> >>>
>> >>> --
>> >>> Claus Ibsen
>> >>> -----------------
>> >>> Red Hat, Inc.
>> >>> Email: [hidden email]
>> >>> Twitter: davsclaus
>> >>> Blog: http://davsclaus.com
>> >>> Author of Camel in Action: http://www.manning.com/ibsen
>> >>>
>> >>
>> >>
>>
>>
>>
>> --
>> Claus Ibsen
>> -----------------
>> Red Hat, Inc.
>> Email: [hidden email]
>> Twitter: davsclaus
>> Blog: http://davsclaus.com
>> Author of Camel in Action: http://www.manning.com/ibsen
>>



--
Claus Ibsen
-----------------
Red Hat, Inc.
Email: [hidden email]
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Reply | Threaded
Open this post in threaded view
|

Re: How to check that a file is empty

Bengt Rodehav
OK - thanks.

/Bengt


2013/8/15 Claus Ibsen <[hidden email]>

> There should be non static methods on simple language to create a
> predicate.
>
> On Thu, Aug 15, 2013 at 1:43 PM, Bengt Rodehav <[hidden email]> wrote:
> > Thanks Claus.
> >
> > I do believe that the "PredicateBuilder.toPredicate" method I use does
> take
> > an expression as a parameter and returns a Predicate. Which method
> should I
> > have used?
> >
> > /Bengt
> >
> >
> >
> >
> > 2013/8/15 Claus Ibsen <[hidden email]>
> >
> >> Hi
> >>
> >> This is because you use the simple language "wrong" as you create an
> >> expression, and NOT a predicate.
> >>
> >> I have logged a ticket to improve on this, so you have static methods
> >> to easily create a predicate
> >> https://issues.apache.org/jira/browse/CAMEL-6639
> >>
> >> On Thu, Aug 15, 2013 at 9:49 AM, Bengt Rodehav <[hidden email]>
> wrote:
> >> > My original code that has been working for 2-3 years looks like this:
> >> >
> >> > *Predicate emptyFile =
> >> > PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
> >> 0"));
> >> >
> >> >
> >>
> interceptFrom().when(emptyFile).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
> >> > *
> >> >
> >> > For some reason, when using Camel 2.11.0, the above code causes all
> files
> >> > to be skipped (even the non-empty ones). I have found another way of
> >> doing
> >> > this that works with Camel 2.11.0. It looks as follows:
> >> >
> >> > *
> >> >
> >>
> interceptFrom().when(header("CamelFileLength").isEqualTo(0)).setHeader("recipient").simple("file://${file:parent}/skipped/${date:now:yyyyMMdd}").recipientList(header("recipient")).stop();
> >> > *
> >> >
> >> > I'm not sure what is happening. Since I have a workaround I'm OK but
> it
> >> > seems like the behaviour of the SimpleLanguage has changed somehow.
> Could
> >> > be a bug or at least something worth documenting.
> >> >
> >> > Any thoughts?
> >> >
> >> > /Bengt
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > 2013/8/14 Bengt Rodehav <[hidden email]>
> >> >
> >> >> Thanks for the tip. It would probably be good enough although I also
> >> want
> >> >> to move the empty files to a dedicated directory to clearly show what
> >> took
> >> >> place.
> >> >>
> >> >> Do you know f the syntax for checking the file length has changed in
> >> >> Simple language (or rather File language)? Looking at the
> documentation
> >> I
> >> >> can't see that I'm doing anything wrong.
> >> >>
> >> >> /Bengt
> >> >>
> >> >>
> >> >> 2013/8/14 Claus Ibsen <[hidden email]>
> >> >>
> >> >>> See also the readLockMinLength option
> >> >>>
> >> >>> On Wed, Aug 14, 2013 at 4:26 PM, Bengt Rodehav <[hidden email]>
> >> wrote:
> >> >>> > I have recently upgraded Camel to version 2.11.0. In my file
> transfer
> >> >>> > services I have used a predicate together with interceptors to
> avoid
> >> >>> > transferring empty files but instead move them into a subfolder
> >> called
> >> >>> > "skipped". However, this has stopped working. My predicate looks
> like
> >> >>> this:
> >> >>> >
> >> >>> > *Predicate emptyFile =
> >> >>> >
> PredicateBuilder.toPredicate(SimpleLanguage.simple("${file:length} ==
> >> >>> 0"));
> >> >>> > *
> >> >>> >
> >> >>> > I'm not exactly sure in what version this functionality broke but
> I'm
> >> >>> sure
> >> >>> > it worked in version 2.7.1.
> >> >>> >
> >> >>> > Is there a better way to do this in Camel 2.11.0?
> >> >>> >
> >> >>> > /Bengt
> >> >>>
> >> >>>
> >> >>>
> >> >>> --
> >> >>> Claus Ibsen
> >> >>> -----------------
> >> >>> Red Hat, Inc.
> >> >>> Email: [hidden email]
> >> >>> Twitter: davsclaus
> >> >>> Blog: http://davsclaus.com
> >> >>> Author of Camel in Action: http://www.manning.com/ibsen
> >> >>>
> >> >>
> >> >>
> >>
> >>
> >>
> >> --
> >> Claus Ibsen
> >> -----------------
> >> Red Hat, Inc.
> >> Email: [hidden email]
> >> Twitter: davsclaus
> >> Blog: http://davsclaus.com
> >> Author of Camel in Action: http://www.manning.com/ibsen
> >>
>
>
>
> --
> Claus Ibsen
> -----------------
> Red Hat, Inc.
> Email: [hidden email]
> Twitter: davsclaus
> Blog: http://davsclaus.com
> Author of Camel in Action: http://www.manning.com/ibsen
>