473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

detecting corrupt/stuffed files (how to?)

Hi
I'm writing a program that needs to read from a file. In order for the
program to be robust, it should somehow check that the file isn't corrupt,
or stuffed in any way. For example, that file may have been created but a
crash occurred at that point in time (while it was being created), damaging
the file. Now, my program which needs to read from this file, should first
check that it's in good condition, and that it hasn't been stuffed up in
any way. What is the normal way of doing this?

thanks in advance
Jole

I'm using Java and am aware of some of those File.XX methods. perhaps the
File.isReadable() methods will fail if the files have been damaged or
corrupted? or another way ?
Jul 17 '05 #1
5 12427
> I'm using Java and am aware of some of those File.XX methods.
perhaps the File.isReadable() methods will fail if the files have
been damaged or corrupted? or another way ?


You won't be able to tell if a file was partially written from a crash.
I'll just abruptly end or contain nothing.

If you control the file structure, you can do such things as put a known
structure at the head of the file which contain "magic words" which must
match, and include items in the header such as file length and checksum
which must match.

Whatever you do, just make sure your reader can handle anything you throw at
it, because users will find a way to do just that! ;)


Jul 17 '05 #2
well, it's really not necessary to go thru the trouble of setting up a
isReadable() method... in fact, from what you have described, i'd be
inclined to advise against it, unless you want to maintain static /
post-mortem data...

for you see, the java i/o libraries have all the "isReadable"
functionality you could ever imagine. and should a file be altered or
damaged or never properly written in the first place, java is more than
capable of detecting something wrong depending on the level of
sensitivity you are interested in.

for simplicity in your design, you should store and retrieve data as
objects as a preference with any object oriented langauge. unless your
application is importing or exporting data this ought to be the default.
the reason being due to the excellent design put into saving objects as
well as detecting any changes to the object image on the restore.

now by objects, i am referring to the Object streaming classes and not
so much a vendor of object databases.

now for whatever reason you should be interested in investigating a
corrupted object stream, you have the flexibility of opening the same
file/stream with a lower level protocol, say a data stream. this will
allow you to examine the bytes without throwing higher level exceptions

finally, the exception mechanism became a main stream procedure in the
object design community for a reason.... namely simplicity in design
with respect to error management. the phylosophy of exceptions is that
you are separating error detection from error handling. this was a major
breakthrew in code design as it allowed developers of commercial
frameworks (or simply previous projects) to identify errors and allow
future programmers to be able to handle future error handling needs
without out having to "change" the origional code.... a lesson well
learned from the days of spagetti design...

i hope this helped

- perry
Jole wrote:
Hi
I'm writing a program that needs to read from a file. In order for the
program to be robust, it should somehow check that the file isn't corrupt,
or stuffed in any way. For example, that file may have been created but a
crash occurred at that point in time (while it was being created), damaging
the file. Now, my program which needs to read from this file, should first
check that it's in good condition, and that it hasn't been stuffed up in
any way. What is the normal way of doing this?

thanks in advance
Jole

I'm using Java and am aware of some of those File.XX methods. perhaps the
File.isReadable() methods will fail if the files have been damaged or
corrupted? or another way ?


Jul 17 '05 #3
well, it's really not necessary to go thru the trouble of setting up a
isReadable() method... in fact, from what you have described, i'd be
inclined to advise against it, unless you want to maintain static /
post-mortem data...

for you see, the java i/o libraries have all the "isReadable"
functionality you could ever imagine. and should a file be altered or
damaged or never properly written in the first place, java is more than
capable of detecting something wrong depending on the level of
sensitivity you are interested in.

for simplicity in your design, you should store and retrieve data as
objects as a preference with any object oriented langauge. unless your
application is importing or exporting data this ought to be the default.
the reason being due to the excellent design put into saving objects as
well as detecting any changes to the object image on the restore.

now by objects, i am referring to the Object streaming classes and not
so much a vendor of object databases.

now for whatever reason you should be interested in investigating a
corrupted object stream, you have the flexibility of opening the same
file/stream with a lower level protocol, say a data stream. this will
allow you to examine the bytes without throwing higher level exceptions

finally, the exception mechanism became a main stream procedure in the
object design community for a reason.... namely simplicity in design
with respect to error management. the phylosophy of exceptions is that
you are separating error detection from error handling. this was a major
breakthrew in code design as it allowed developers of commercial
frameworks (or simply previous projects) to identify errors and allow
future programmers to be able to handle future error handling needs
without out having to "change" the origional code.... a lesson well
learned from the days of spagetti design...

i hope this helped

- perry
Jole wrote:
Hi
I'm writing a program that needs to read from a file. In order for the
program to be robust, it should somehow check that the file isn't corrupt,
or stuffed in any way. For example, that file may have been created but a
crash occurred at that point in time (while it was being created), damaging
the file. Now, my program which needs to read from this file, should first
check that it's in good condition, and that it hasn't been stuffed up in
any way. What is the normal way of doing this?

thanks in advance
Jole

I'm using Java and am aware of some of those File.XX methods. perhaps the
File.isReadable() methods will fail if the files have been damaged or
corrupted? or another way ?


Jul 17 '05 #4

"perry" <ye*******@yahoo.com> wrote in message
news:%9********************@news20.bellglobal.com. ..
well, it's really not necessary to go thru the trouble of setting up a
isReadable() method... in fact, from what you have described, i'd be
inclined to advise against it, unless you want to maintain static /
post-mortem data...

for you see, the java i/o libraries have all the "isReadable"
functionality you could ever imagine. and should a file be altered or
damaged or never properly written in the first place, java is more than
capable of detecting something wrong depending on the level of
sensitivity you are interested in.

for simplicity in your design, you should store and retrieve data as
objects as a preference with any object oriented langauge. unless your
application is importing or exporting data this ought to be the default.
the reason being due to the excellent design put into saving objects as
well as detecting any changes to the object image on the restore.

now by objects, i am referring to the Object streaming classes and not
so much a vendor of object databases.

now for whatever reason you should be interested in investigating a
corrupted object stream, you have the flexibility of opening the same
file/stream with a lower level protocol, say a data stream. this will
allow you to examine the bytes without throwing higher level exceptions

finally, the exception mechanism became a main stream procedure in the
object design community for a reason.... namely simplicity in design
with respect to error management. the phylosophy of exceptions is that
you are separating error detection from error handling. this was a major
breakthrew in code design as it allowed developers of commercial
frameworks (or simply previous projects) to identify errors and allow
future programmers to be able to handle future error handling needs
without out having to "change" the origional code.... a lesson well
learned from the days of spagetti design...

i hope this helped

- perry
Jole wrote:
Hi
I'm writing a program that needs to read from a file. In order for the
program to be robust, it should somehow check that the file isn't corrupt, or stuffed in any way. For example, that file may have been created but a crash occurred at that point in time (while it was being created), damaging the file. Now, my program which needs to read from this file, should first check that it's in good condition, and that it hasn't been stuffed up in
any way. What is the normal way of doing this?

thanks in advance
Jole

I'm using Java and am aware of some of those File.XX methods. perhaps the File.isReadable() methods will fail if the files have been damaged or
corrupted? or another way ?


By default you should NOT serialize objects to store information. Apart from
poor performance and terrible integration characteristics with other
programs (the main appeal of Unix was that is was very easy to combine all
programs because they could read each others output and generate output
themselves that was also readable) it creates a very tight coupling between
class versions and file formats.

Object serialization is usually propagated by "OO-purists" who dislike the
fact that data is not stored as an "object". Although it has its application
areas people should think twice before using it.

For simple data consider plain text,. for complexer data structures consider
XML and ALWAYS consider a relational database system. Most successfull
software systems of this world use a combination of these.

Silvio Bierman

Jul 17 '05 #5
> For simple data consider plain text,. for complexer data structures
consider XML and ALWAYS consider a relational database system. Most
successfull software systems of this world use a combination of these.


GREAT point. You will never "lock yourself out" of your own system if you
can get in it through notepad!

Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Hal Vaughan | last post by:
I am writing out archive files using ZipOutputStream with the following code: aEntry is a global Array of ZipEntries llData is a LinkedList of the data corresponding to the the ZipEntry of the...
5
by: Vinay | last post by:
Hi I have a corrupt word file. I am able to open it with the code given below tr Dim pInfo As System.Diagnostics.ProcessStartInfo = New System.Diagnostics.ProcessStartInfo( pInfo.UseShellExecute...
4
by: SS | last post by:
We built an MSI file to deploy a .net app to the workstation. We created an HTML page that has a link to the MSI file. On a very sporadic basis, when the MSI is run we get the following message:...
6
by: Annette Massie | last post by:
I have an 2000 database that is getting corrupt many times a day. The application is sittin on a network with about 5 users accessing it. Most times I get a call with the user saying the...
2
by: Sam-Kiwi | last post by:
I've spent the last 6 months developing a pay-per-download website using ASP.NET Users purchase documents and then download them. The intention is that users are only charged for documents...
1
by: Jack Orenstein | last post by:
My company is developing a PostgreSQL 7.4 application. We don't want our customers to have to manage the database, so we're automating as much maintenance as possible. If the database ever becomes...
3
by: Nathan Sokalski | last post by:
I have several pieces of data that I use the HttpApplicationState for, because they rarely change and are used by everyone. When these pieces of data are created, they are created either from...
17
by: shineofleo | last post by:
Here is the situation: I wrote a VB programm, which stores all the information in a single Access database file using jet engine. It worked well, however one of my customs reported that there was...
0
by: Fredo | last post by:
I have an app that I'm writing to manage jpgs. Sometimes the photos are corrupt. If I use something like ACDSee, it will show the image, but it will have a note in the status bar that the image is...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.