Sitemap

Amicuk Programming Answers

Problem working with binary file

2015-10-11   Views:1

Advertisement

Hi, I have two seperate programs. The first one: *Reads a  PDF file from disk via InputStreamReader.read(char[]) *converts it to s String [String.valueOf(char[])] connects to other program using Socket and writes the string's bytes to the OutputStrea

Hi,
I have two seperate programs.
The first one:
*Reads a  PDF file from disk via InputStreamReader.read(char[])
*converts it to s String [String.valueOf(char[])]
connects to other program using Socket and writes the string's bytes to the OutputStream of the Socket (socket.getOutputStream().write(string.getBytes);)
Second one:
*Reads the file from socket via BufferedReader.read(char[])
*converts it to a string via String.valueOf()
*writes it to a file using FileOutputStream.write(content.getBytes())
The problem is:
If the secong program is running on Win2K,the PDF file is opened with no errors but the pages are all blank.But everything is OK if it is running on Unix(IBM AIX java ver 1.3.1)
First program is always on Win2K.
I compared the win2k and unix PDF files,some nonprintable chars are displayed as ? in the win2K one,
what can be the reason? why does the same problem not occur on Unix?
Some problems are mentioned on web/forums but these are related with browsers or servlets which I am not using in this case.
Thanks in advance,

The replay answer
Advertisement
PDF is a binary file.
You're doing 1 of 2 possible things wrong....
1) trying to read a binary file as a text file ( string )
You can't "just read" a binary file as a text file to extra the strings.
You need to get the binary format, and parse it's format properly to extract the
string data.
2) trying to send a binary file across a socket as a string
You need to read the PDF file as an array of bytes and send them across
the socket as such. Trying to convert binary data to characters / strings
is wrong. characters get converted to and from native encoding schemes to
unicode.... among other problems.
regards,
Owen

Go to See the other 6 answers

Problem working with binary file

Category:DefaultRelease time:2015-10-11Views:130

Hi, I have two seperate programs. The first one: *Reads a  PDF file from disk via InputStreamReader.read(char[]) *converts it to s String [String.valueOf(char[])] connects to other program using Socket and writes the string's bytes to the OutputStrea[More]

Urgent - pls help - Problem while inserting binary file into Oracle DB

Category:DefaultRelease time:-0001-11-30Views:130

Hi, I am trying to insert binary files into a Blob column in a Oracle 10G table. The binary files would be uploaded by the web users and hence come as multipart request. I use apache commons upload streaming API to handle it. Finally i am getting a i[More]

Binary file readed from Labview and Borland C++ v.5

Category:DefaultRelease time:-0001-11-30Views:130

Hi Everybody! My problem is reading binary file from Labview 7.0 and Borland C++ version 5 is not the same. Only one difference is "space". Reading from Labview I got "00" (decimal) and reading from Borland C++ I got "32". I[More]

Problem when streaming out a binary file

Category:DefaultRelease time:2015-10-11Views:130

Hi, I am trying to stream out a binary file to an output stream (not a file, but a socket). My file is a gzip file, and I was initially simply trying to open the file, read it to a a byte array, and writing it out to my output stream. However, I got[More]

Problems with binary files

Category:DefaultRelease time:2015-10-11Views:130

Hello everybody! I'm having deep trouble with reading from binary files. I have opened a DataInputStream with a FileInputStream to read the data (which consists of a lot of short-Variables) into my program. Then I wondered why the data read is always[More]

Binary file problem (Read a specific Stream)

Category:DefaultRelease time:-0001-11-30Views:130

Hi Guys , I have a problem , I want to read a binary files but not the whole binary file. I only want to read one stream. Forexample , I have a binar files which has 5 streams. If I only want to read one of the stream what should i do ? How do i get[More]

Problems writing a structured binary file...

Category:DefaultRelease time:-0001-11-30Views:130

Hi Folks, I've been working with one of my students to convert this matlab routine into a VI to no avail: fwrite(fout,version,'char'); fwrite(fout,nchar_text,'short'); % convert wave_text into array of ascii integers fwrite(fout,wave_text,'char'); %[More]

Problem saving 2D array to binary file

Category:DefaultRelease time:-0001-11-30Views:130

I am getting some strange results when trying to write a transposed 2D array of Unisgned 8-bit data to a binary file. Attached is an example program ("071026_ArraySave_Bug.vi") which demonstrates the suspicious behavior. The program generates a[More]

Problem rendering certain bytes when reading binary file

Category:DefaultRelease time:-0001-11-30Views:130

I have a two part problem. I am trying to read files of any type from a client and transfer them over a pipe to a UNIX host running a C API. I have this process working for text data just fine however when I try and submit binary data there appears t[More]

Getting problem while editing a binary file

Category:DefaultRelease time:-0001-11-30Views:130

Hi All, I am trying to edit a binary file using Java.The file contain a string that I have to replace with some other string.For exanple let us assume following is the content of the file - õgëÓÌ©™ÿÿ ABC õgëÓÌ©™ÿÿ Here, I have to replace this ABC(a[More]

Binary File IO DLL Problem

Category:DefaultRelease time:-0001-11-30Views:130

Hiii     I have developed one Binary file Read/Write Vi..  and then i have convert that vi in to DLL......     Now i tested that DLL Vi  it is showing an error No 74. Actually for Binary write i will convert the Input cluster to Flattern to String an[More]

Hot
I can't figure out how to downsize my photos for a website that won't take anything above 3MB my Photos are 4MB. Even when I send them in an email, they are too big to send more than 3 at a time and I don't know how to fix it! Help says that when I s [More]
I have a hydrolic system(in closed loop mode) controlled by a 7344s analog output. a value changes depending on the voltage from the 7344: positive voltage lets water into the system negative voltage lets water out of the system. due to the design of [More]
Hello All, I noticed that I am able to delete the components from the Components tab of a Service Order even after I have completely issued the components. Is there a possible way to prevent deletion of components that have already been issued..? I t [More]
We are facing an issue with our packing list for a division we are going live with in three weeks.  Our current business process for our plants already on SAP is to create the Packing List when the Delivery is created, with timing code "3" in th [More]
I downloaded the latest version of hp support assistant with all the security disabled ie trend micro windows firewall and windows defender and when i went to use the support assistant it shows no product name or number and it goes through a scan pro [More]
Photos that I take on my iPhone 4 are showing up in the Photo Stream on that device and on my iPad but not in iPhoto, at least not for a long time (hours or days). Quitting and restarting iPhoto doesn't help. Yes, Photo Stream is turned on in iPhoto [More]
I made a quicktime movie using File>Export>Quicktime Conversion... in FCP using H.264 compression codec with best video quality and 16-bit audio. video was originally captured in miniDV. Self contianed movie was made and looked pretty good in Quickt [More]
I suggest everyone trying to play Second Life on their MacBook late 2007 or anyone having the freezing issue to post here: https://jira.secondlife.com/browse/VWR-3494 Log in using your Second Life name and Password, on the left side of the page click [More]
Our client has multiple company codes in different companies. The local currencies are different for each country's co codes Group currency is USD At year end, when they run financials in F.01, in the consolidation ledger 0L, they first run with curr [More]
Hi. This may be a dumb question, but I haven't been writing code all that long. Anyway, I am creating a custom online store. I used the spry menu bar to create a menu bar for the product categories. The tutorials I had been watching about how to use [More]