aspose file tools*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes IOException thrown Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "IOException thrown" Watch "IOException thrown" New topic
Author

IOException thrown

Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

Baring in mind that all variables are initialized correctly and all exceptions are being handled:



why is an IOException being thrown on the line marked //<----- HERE ??


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, SCJD, SCEA/OCMJEA

Live life to an interface, not an implementation!
Ronald Wouters
Ranch Hand

Joined: Apr 28, 2005
Posts: 190
Can you post the complete stacktrace of the IOException please. That might give the rest of us a better idea of what is going on ...



Sun Certified Developer for the Java 2 Platform
Sun Certified Enterprise Architect for the Java Platform, Enterprise Edition 5
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

Well i traced back to where the actual exception was thrown and it was where the line marked HERE is in the readFully method. ???



?

Regards.
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hello,

what value of fieldnameLength are you reading?
is the exception thrown in the first iteration?
how many iterations are you performing?

Verify you are reading "expected" values for these vars,

Regards


SCJP, OCMJD, OCMJEA
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

Here is my output (after i inserted various print statements):



fieldnameLength = 4
i = 0
fieldNames = 4 //length

fieldnameLength = 64
i = 1
fieldNames = 64

fieldnameLength = 8224
i = 2
fieldNames = 8224

Input / Output error with file: C:\db-1x1.db :null


[ September 29, 2005: Message edited by: Marzo Kaahn ]
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Obviously 8224 bytes for a fieldName is too long.
Is your header section well readed (int,int, short)?
Are you sure your file cannot be corrupted?
Saheed Adepoju
Ranch Hand

Joined: Jun 23, 2004
Posts: 267
Hi
Wow That's large for a fieldlength! Make sure you are reading the db file according to the schema you have! If it doesnt work! Reboot your machine maybe(might help)!


Saheed Adepoju<br />SCJP 1.4<br />SCJD (B&S..In progress)
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

When i open my db file i see this:
#######�####name#@##location#@##size####smoking####rate####date#
##owner##

It seems to me as if it is reading "name" and "location" and reading the rest all together.

Could the file corrupt itself by simply opening it in some text area?

What could be happening here?
[ September 29, 2005: Message edited by: Marzo Kaahn ]
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

Hi Marzo,
you can redownload your assignment.
I have done that twice.
Be aware that the asignment version matches the first download.
However send an email to Sun telling what are you going to do

Let us know what's happens then...

Regards
[ September 29, 2005: Message edited by: Oricio Ocle ]
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

Please excuse me if i am revealing too much code, but i'd like to know whether it is my code or whether the db file is corrupt.

My db specs are:


The format of data in the database file is as follows:

Start of file
4 byte numeric, magic cookie value. Identifies this as a data file
4 byte numeric, total overall length in bytes of each record
2 byte numeric, number of fields in each record

Schema description section.
Repeated for each field in a record:
2 byte numeric, length in bytes of field name
n bytes (defined by previous entry), field name
2 byte numeric, field length in bytes
end of repeating block

Data section.
Repeat to end of file:
1 byte "deleted" flag. 0 implies valid record, 1 implies deleted record
Record containing fields in order specified in schema section, no separators between fields, each field fixed length at maximum specified in schema information

End of file


My (rough) implementation:



Output:

magicCookie: 257
sizeBytes: 159
numFields: 7
IOException thrown!

All i want to do for now is at least store the field names for futher testing.

Any ideas?

Thanks in advance,
Marzo.
Oricio Ocle
Ranch Hand

Joined: Nov 30, 2004
Posts: 284

hey hey





are you sure?

Regards
Gary Hellman
Greenhorn

Joined: Sep 24, 2005
Posts: 11
Like Oricio said -

You may want to print out all your variables at this stage -
so you can see how big you are allocating the byte arrays, etc.

and the loop has to account for all the repeating fields and their parts.

You are probably getting the first field name - but then the one byte
will not be enough to "soak up" all the other field name "parts"
before the next field name.


Thanks<br />Gary<br />SCJP 1.4
Marcelo Ortega
Ranch Hand

Joined: May 31, 2005
Posts: 519

Thanks people, i got it, i was reading a byte instead of a short at the end of the loop.

Thanks again.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: IOException thrown