Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [aspectj-users] AspectJ and inputstream

Andy, 

Thank you!! That did it.

Al

-----Original Message-----
From: aspectj-users-bounces@xxxxxxxxxxx
[mailto:aspectj-users-bounces@xxxxxxxxxxx] On Behalf Of Andy Clement
Sent: Tuesday, January 20, 2009 6:18 PM
To: aspectj-users@xxxxxxxxxxx
Subject: Re: [aspectj-users] AspectJ and inputstream

oops, ignore that rogue return

void around(InputStream is): execution(* bar(..)) && args(is) {
    String l = readContents(is);
    ByteArrayInputStream bais = new ByteArrayInputStream(l.getBytes());
    proceed(bais);
}

just tried it and it worked for me.

2009/1/20 Andy Clement <andrew.clement@xxxxxxxxx>:
> Your before() advice is simply assigning the advice local variable
> called 'is', it won't affect the advised location.  You could use
> around advice to do that.
>
> void around(InputStream is): execution(* bar(..)) && args(is) {
>  String l = readContents(is);
>  ByteArrayInputStream bais = new ByteArrayInputStream(l.getBytes());
>  return proceed(bais);
> }
>
> Andy.
>
> 2009/1/20 Al Aghili <aaghili@xxxxxxxxxxxxxxxxxx>:
>>
>>
>> Hi,
>> I'm having an issue trying to read an inputstream data in my aspect and
then
>> setting the input stream object to a new object. This doesn't work
>>
>> Here is the sample code
>>
>> public class AspectSampleMain {
>> public static void main(String[] args) {
>>                 // TODO Auto-generated method stub
>>                 String test = "hello world
>> askdjlasdkjaldkjasldkjalsdkjaslkdjalskjdslakjd dsjalkjd";
>>         ByteArrayInputStream bais = new
>> ByteArrayInputStream(test.getBytes());
>>         InputStream is = bais;
>>        bar(is);
>>
>> }
>> public static void bar(InputStream is){
>>         String l =  readContent(is);
>>                System.out.println(l); // l is blank this is wrong because
is
>> has been read.
>> }
>> }
>> Here is my aspect
>> public aspect AspectSample {
>>         pointcut sample(java.io.InputStream is):
>>     execution(* AspectSampleMain.bar( .. ))
>>     && args(is);
>>
>>     before (java.io.InputStream is):sample(is){
>>
>>     String l =  readContent(is);
>>              ByteArrayInputStream bais = new
>> ByteArrayInputStream(l.getBytes());
>>              is = bais;
>>
>>     }
>> }
>>
>> This does not work as the "is" does not get set to bais after the aspect
>> returns to the bar() code. So the input stream has been read and can't be
>> re-read again.
>>
>> How do I get around this.
>>
>> Thanks
>> Al
>>
>> _______________________________________________
>> aspectj-users mailing list
>> aspectj-users@xxxxxxxxxxx
>> https://dev.eclipse.org/mailman/listinfo/aspectj-users
>>
>>
>
_______________________________________________
aspectj-users mailing list
aspectj-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/aspectj-users



Back to the top