Skip to content
Advertisement

ObjectStream’s magic number in the header is changed while putting file on a linux server

Hope you are doing well. The strange thing happened to me since yesterday.

I have the following code for saving the JSON.

JavaScript

and the following code for reading it.

JavaScript

I’m writing the JSON via saveCacheJson and then putting the file to my Server (Linux) and then my ‘front end’ part downloads it and tries to read.

From yesterday I started receiving the following exception.

JavaScript

After some research and trying to understand what’s going on I found the following.

There is a MAGIC_NUMBER in the ObjectOutputStream class, that used for a header.

JavaScript

Then, in the ObjectInputStream class the following method is called.

JavaScript

And the exception is thrown here.

So, I opened the file that I write on my local machine (Mac OS) and found the first 2 bytes that are the following

JavaScript

Then I tried the following in the terminal.

JavaScript

and found that the first 2 bytes are right. Here is it.

JavaScript

So, I tried to do the same for the downloaded file (from Linux server, that I put there before) and found that the first 2 bytes are wrong. So, I checked the flow and found that they have changed during copying the file to the server.

This is strange overall, but the strangest thing is that it worked for about 10 days ago. As I remember, nothing changed in my server.

So, my main question is

ANY IDEAS WHY THE STREAM HEADER IS CHANGED DURING UPLOAD TO LINUX SERVER???

Thanks.

UPDATE

The first 2 shorts in the file BEFORE UPLOAD are.

JavaScript

Which is right.

The first 2 shorts in the file AFTER UPLOADING to linux from Mac are.

JavaScript

Which is wrong.

UPDATE 2.

The result from the right file.

JavaScript

And from the Wrong file.

JavaScript

Advertisement

Answer

OK, I found what causes the problem. Not sure why yet, but found how to solve.

I used mypath/myfile.txt as a pathToCache parameter for the saveCacheJson method. So, I found that the problem because of the .txt extension. I removed an extension at all and the problem resolved. It seems the .txt extension is the reason, that Mac’s system doesn’t understand that the file is binary and trying to encode its content during copying. Not sure why the system trying to change the file’s content at all during the copy ))

Advertisement