"dhartford" wrote : Hi andrzejros,
| I'm glad you are tackling your problem with EMB! Unfortunately, I have only been
working on some other parts (sporadically and rarely) with EMB and do not have
anything in production yet.
|
| Your code does look correct. Only thing might be related to the
'arrayindexoutofbounds' problem could be either the bytearray (if the image is small,
maybe set the bytearray size smaller), or there really is a problem in the EMB
implementation.
|
| Haven't seen anyone respond back to you, so at least letting you know one person
is watching, so don't get discouraged! :-)
|
| -D
Thank You for response, I have some more informations:
1. content fetched via getContent() method is returned correctly
2. content returned via readContent(position, buffer, offset, length) is returned
correctly BUT only if whole content is read, if content is read as mentioned below,
exception is thrown
3. when ivocation is made like this:
| byte[] buffer = new byte[(int) media.getSize()/2];
| long position = 0;
| int bytesRead = 0;
|
| while((bytesRead = media.readContent(position, buffer))!=-1)
| {
| Logger.getLogger(this.getClass()).warn("read: " + bytesRead);
| position += bytesRead;
| }
|
error is thrown, after code analysis, bug is located here:
| System.arraycopy(content, (int) position, buffer, offset, length);
| return content.length;
|
so allways is returned WHOLE siez of content - but not actualy copied!
so after second read, we are realy tryng to fetch data after allocated content, due to
emb spec methods readContent(...) (both) returns invalid bytes read length and also
System.arraycopy is not suitable to this job invocated this way - arrayout of bounds
is allways thrown when you are trying to copy from source more than available bytes
ie. content length = 11, position = 10 buffer = 2, length = 2 so we have one byte 'out
of bounds' - method is unsafe, length parameter should be calculated dynamicaly -
copied from IBM RI - i think that this is shortest way to do it:
| public int readContent(long position, byte[] buffer, int offset, int length)
throws MediaException {
| if(buffer == null)
| throw new NullPointerException("buffer is null");
| if ((position < 0 ) || (offset < 0) ||(position > this.getSize())) {
| throw new IndexOutOfBoundsException("offset is negitive or position is negitive or
exceeds content size");
| } else if (offset >= buffer.length) {
| throw new IndexOutOfBoundsException("offset is greater than buffer length");
| } else if (position == this.getSize()) {
| return -1;
| } else {
| if (length<0)
| throw new NegativeArraySizeException("length is negitive");
| length = Math.min(length, (int) (this.getSize() - position));
| length = Math.min(length, buffer.length - offset);
| byte[] content = this.getCmpContent();
| if (content == null){
| throw new ContentAccessException("content is null");
| }
| System.arraycopy(content, (int) position, buffer, offset, length);
| return length;
| }
| }
|
View the original post :
http://www.jboss.org/index.html?module=bb&op=viewtopic&p=3849890#3849890
Reply to the post :
http://www.jboss.org/index.html?module=bb&op=posting&mode=reply&p=3849890
-------------------------------------------------------
This SF.net email is sponsored by: IT Product Guide on ITManagersJournal
Use IT products in your business? Tell us what you think of them. Give us
Your Opinions, Get Free ThinkGeek Gift Certificates! Click to find out more
http://productguide.itmanagersjournal.com/guidepromo.tmpl
_______________________________________________
JBoss-Development mailing list
[EMAIL PROTECTED]
https://lists.sourceforge.net/lists/listinfo/jboss-development