Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
IOException while reading a raw resource.
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  12 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Jonathan  
View profile  
 More options Aug 13 2009, 1:36 pm
From: Jonathan <jon.aposto...@gmail.com>
Date: Thu, 13 Aug 2009 10:36:52 -0700 (PDT)
Local: Thurs, Aug 13 2009 1:36 pm
Subject: IOException while reading a raw resource.
I'm running into a strange problem while reading from an InputStream
on the Android platform. I'm not sure if this is an Android specific
issue, or something I'm doing wrong in general.

The only thing that is Android specific is this call:

InputStream is = getResources().openRawResource(R.raw.myfile);

This returns an InputStream for a file from the Android assets.
Anyways, here's where I run into the issue:

bytes[] buffer = new bytes[2];
is.read(buffer);

When the read() executes it throws an IOException. The weird thing is
that if I do two sequential single byte reads (or any number of single
byte reads), there is no exception. Ie, this works:

byte buffer;
buffer = (byte)buffer.read();
buffer = (byte)buffer.read();

Any idea why two sequential single byte reads work but one call to
read both at once throws an exception? The InputStream seems fine...
is.available() returns over a million bytes (as it should).

Stack trace shows these lines just before the InputStream.read():

java.io.IOException
at android.content.res.AssetManager.readAsset(Native Method)
at android.content.res.AssetManager.access$800(AssetManager.java:36)
at android.content.res.AssetManager$AssetInputStream.read
(AssetManager.java:542)

Changing the buffer size to a single byte still throws the error. It
looks like the exception is only raised when reading into a byte
array.

Any help is appreciated! Thanks!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan  
View profile  
 More options Aug 13 2009, 3:30 pm
From: Jonathan <jon.aposto...@gmail.com>
Date: Thu, 13 Aug 2009 12:30:47 -0700 (PDT)
Local: Thurs, Aug 13 2009 3:30 pm
Subject: Re: IOException while reading a raw resource.
If I truncate the file to 100,000 bytes (file is: 1,917,408 bytes
originally) it works fine.  Is there a problem with files over a
certain size?

On Aug 13, 10:36 am, Jonathan <jon.aposto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan  
View profile  
 More options Aug 13 2009, 3:35 pm
From: Jonathan <jon.aposto...@gmail.com>
Date: Thu, 13 Aug 2009 12:35:39 -0700 (PDT)
Local: Thurs, Aug 13 2009 3:35 pm
Subject: Re: IOException while reading a raw resource.
I was able to load a 1MB file okay, but 1.5MB crashed.

On Aug 13, 12:30 pm, Jonathan <jon.aposto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Andrei  
View profile  
 More options Aug 13 2009, 3:46 pm
From: Andrei <gml...@gmail.com>
Date: Thu, 13 Aug 2009 12:46:11 -0700 (PDT)
Local: Thurs, Aug 13 2009 3:46 pm
Subject: Re: IOException while reading a raw resource.
1048576 is the file limit
If you have bigger file split it

On Aug 13, 3:35 pm, Jonathan <jon.aposto...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan  
View profile  
 More options Aug 13 2009, 3:52 pm
From: Jonathan <jon.aposto...@gmail.com>
Date: Thu, 13 Aug 2009 12:52:00 -0700 (PDT)
Subject: Re: IOException while reading a raw resource.
Is that a restriction on InputStream, or for assets?  I was able to
include an MP3 file as a resource and it would play just fine
(although I didn't open it via InputStream)... the MP3 was about 3mb.

On Aug 13, 12:46 pm, Andrei <gml...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Proctor  
View profile  
 More options Aug 13 2009, 5:09 pm
From: Jason Proctor <jason.android.li...@gmail.com>
Date: Thu, 13 Aug 2009 14:09:13 -0700
Local: Thurs, Aug 13 2009 5:09 pm
Subject: [android-developers] Re: IOException while reading a raw resource.
why is there a 1mb file limit in this case?

and is the restriction 1mb in the amount of stuff read, or in the
size of the file?

could you maybe open the file, skip a megabyte, then continue to read
the second megabyte?

>1048576 is the file limit
>If you have bigger file split it

--
jason.software.particle

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan  
View profile  
 More options Aug 13 2009, 5:14 pm
From: Jonathan <jon.aposto...@gmail.com>
Date: Thu, 13 Aug 2009 14:14:28 -0700 (PDT)
Local: Thurs, Aug 13 2009 5:14 pm
Subject: Re: IOException while reading a raw resource.
I'm not exactly sure... I'm actually only reading the file 24 bytes at
a time, so I'm not quite sure why the IOException is thrown.  I'm
never allocating a buffer for the full file.

If I do two sequential one byte reads it's fine... but a single 2 byte
read (using read(byte[])) it throws the exception.  The exception is
thrown by AssetManager.readAsset.

On Aug 13, 2:09 pm, Jason Proctor <jason.android.li...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jason Proctor  
View profile  
 More options Aug 13 2009, 5:25 pm
From: Jason Proctor <jason.android.li...@gmail.com>
Date: Thu, 13 Aug 2009 14:25:05 -0700
Local: Thurs, Aug 13 2009 5:25 pm
Subject: [android-developers] Re: IOException while reading a raw resource.
yeah, looking at AssetManager.java, read() calls native
readAssetChar(), whereas read(byte[]) calls native readAsset().
readAsset() throws the IOException if the underlying Asset.read()
returns negative. readAssetChar() just returns negative if the read()
fails, no throw.

Asset.h has UNCOMPRESS_DATA_MAX set to a megabyte in the Android
case, which might be a clue. AFAICS UNCOMPRESS_DATA_MAX isn't
referenced anywhere else in the core code though (?).

i can't spend any more time digging right now. can someone from the
droid team comment? i don't really want my application falling over
at a future date because some asset went over a megabyte. which is
quite likely.

--
jason.software.particle

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan  
View profile  
 More options Aug 13 2009, 6:00 pm
From: Jonathan <jon.aposto...@gmail.com>
Date: Thu, 13 Aug 2009 15:00:03 -0700 (PDT)
Local: Thurs, Aug 13 2009 6:00 pm
Subject: Re: IOException while reading a raw resource.
Someone on StackOverflow responded to my question there and mentioned
it's a problem with compressed files.  If the file is stored
uncompressed it works.  In order to do this (per their suggestion) I
renamed my file to .mp3, which is a known compressed format to
android, and the reads work.

It sounds like we need a way to specify these formats ourself, or to
force a file to not be compressed during the packaging process.
Either that or lift the 1MB restriction.

On Aug 13, 2:25 pm, Jason Proctor <jason.android.li...@gmail.com>
wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile  
 More options Aug 13 2009, 6:05 pm
From: Mark Murphy <mmur...@commonsware.com>
Date: Thu, 13 Aug 2009 18:05:02 -0400
Local: Thurs, Aug 13 2009 6:05 pm
Subject: Re: [android-developers] Re: IOException while reading a raw resource.

Jonathan wrote:
> Someone on StackOverflow responded to my question there and mentioned
> it's a problem with compressed files.

Uh, hi!

Actually, I said "IIRC" it is a problem with compressed files. You'd
have to give it a shot to confirm my memory.

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Need Android talent? Ask on HADO! http://wiki.andmob.org/hado


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Jonathan  
View profile  
 More options Aug 13 2009, 6:09 pm
From: Jonathan <jon.aposto...@gmail.com>
Date: Thu, 13 Aug 2009 15:09:36 -0700 (PDT)
Local: Thurs, Aug 13 2009 6:09 pm
Subject: Re: IOException while reading a raw resource.
Right, you did say that, but as I mentioned I tested it and you were
absolutely right.  Everything worked when I changed the extension
to .mp3.

Thanks for your help!

On Aug 13, 3:05 pm, Mark Murphy <mmur...@commonsware.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Mark Murphy  
View profile  
 More options Aug 13 2009, 6:14 pm
From: Mark Murphy <mmur...@commonsware.com>
Date: Thu, 13 Aug 2009 18:14:12 -0400
Local: Thurs, Aug 13 2009 6:14 pm
Subject: Re: [android-developers] Re: IOException while reading a raw resource.

Jonathan wrote:
> Right, you did say that, but as I mentioned I tested it and you were
> absolutely right.  Everything worked when I changed the extension
> to .mp3.

Ah, sorry, I thought you were just paraphrasing -- I hadn't realized you
tried it.

On the minus side, aapt does not appear to have a command-line switch to
control this behavior (though I suspect Xav would be happy to see a patch).

On the plus side, remembering this correctly means I haven't killed off
all my brain cells yet! Who-hoo! ;-)

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://twitter.com/commonsguy

Need Android talent? Ask on HADO! http://wiki.andmob.org/hado


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »