I can't save xlsx file getting No more data to read from socket error

hi

I can put the data to sheets and even calculateFormula and get new data back. There is only the problem with saving...

How can I use BiteArrayOutputStream to work with the file? could you please give me a link to documentation or something?

thanks

Hi,

To use ByteArrayOutputStream for your situation, please see following code example:

C#


ByteArrayOutputStream baos = new ByteArrayOutputStream();

wb.save(baos, SaveFormat.XLSX);

byte[] data = baos.toByteArray();

FileOutputStream fos = new FileOutputStream(p_file_path+“saved.xlsx”);

fos.write(data);

fos.close();

still the same error…

Hi,

Please give us more details about the exception stack trace. For the code:

ByteArrayOutputStream baos = new ByteArrayOutputStream();
wb.save(baos, SaveFormat.XLSX);
byte[] data = baos.toByteArray();
FileOutputStream fos = new FileOutputStream(p_file_path+"saved.xlsx");

where the exception was thrown? At the line of “wb.save...” or “new FileOutputStream(...”?


Thank you.

the message is thrown here:

CellsHelper.setFontDir("/tmp/Fonts");


and there is nothing in stack error file. In fact, it doesn't create error stack file because it can't even reach Catch section

Hi,

It is strange that CellsHelper.setFontDir() caused such kind of error. In fact CellsHelper.setFontDir() does not use any IO operation. The specified font dirs only be accessed when user begin to use render or measure features.

Anyway, please remove the code of CellsHelper.setFontDir() and try your application again to test whether your code can work.

mshakeel.faiz:
Anyway, please remove the code of CellsHelper.setFontDir() and try your application again to test whether your code can work.

In this case there is a stack output:

java.lang.IllegalArgumentException: Cannot find required font defination[Family:Calibri, Style:0]. Please specify font path.
at com.aspose.cells.a.d.co.b(Unknown Source)
at com.aspose.cells.a.d.V.a(Unknown Source)
at com.aspose.cells.pj.a(Unknown Source)
at com.aspose.cells.rd.a(Unknown Source)
at com.aspose.cells.rd.a(Unknown Source)
at com.aspose.cells.Worksheet.autoFitRow(Unknown Source)
at com.aspose.cells.lY.a(Unknown Source)
at com.aspose.cells.gr.a(Unknown Source)
at com.aspose.cells.gr.C(Unknown Source)
at com.aspose.cells.gr.a(Unknown Source)
at com.aspose.cells.gq.a(Unknown Source)
at com.aspose.cells.Workbook.a(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at com.aspose.cells.Workbook.save(Unknown Source)
at xxCells.Sav(xxCells:297)

Hi,

Would you please test the code CellsHelper.setFontDir() itself? That is, please remove all other api invocations, in your application there is only one line code:


CellsHelper.setFontDir(…);


If you can get the socket error again, please try to access the specified font dir by java common IO APIs. Such as:

for(File ff = new File("/tmp/Fonts").listFiles())
{
byte[] data = new byte((int)ff.length());
FileInputStream fis = new FileInputStream(ff);
fis.read(data);
fis.close();
}

mshakeel.faiz:
Hi,

Would you please test the code CellsHelper.setFontDir() itself? That is, please remove all other api invocations, in your application there is only one line code:

CellsHelper.setFontDir(...);



no erros after that, passed silently...

Hi,

Then it seems it is not the code of CellsHelper.setFontDir() that caused the issue. How about accessing the files @ your specified path? Did you test the code we gave in previous post for accessing files by Java’s common IO APIs?

Thank you.

Amjad Sahi:

Hi,<?xml:namespace prefix = o />

Then it seems it is not the code of CellsHelper.setFontDir() that caused the issue. How about accessing the files @ your specified path? Did you test the code we gave in previous post for accessing files by Java’s common IO APIs?

Thank you.

I've just discovered that it crushed after adding workbook constructor:

CellsHelper.setFontDir("/tmp/tmp2/Fonts");
Workbook workbook = new Workbook(p_file_path);

All IO operations go well without Workbook class.

So that's what we have:

working:

//CellsHelper.setFontDir("/tmp/tmp2/Fonts");
Workbook workbook = new Workbook(p_file_path);

working:

CellsHelper.setFontDir("/tmp/tmp2/Fonts");
//Workbook workbook = new Workbook(p_file_path);

not working:

CellsHelper.setFontDir("/tmp/tmp2/Fonts");
Workbook workbook = new Workbook(p_file_path);

Hi,


Thanks for your feedback.

We have logged it to add your comments with your issue. We will look into it further.

Thank you.

Hi,

We need you to test the code which we provided with reply at this post. Please test whether you can access those font files firstly by that code.

mshakeel.faiz:
Hi,

We need you to test the code which we provided with reply at this post. Please test whether you can access those font files firstly by that code.

I've tested it and it has no errors, acces is OK

Hi,

Thanks for your feedback.

We have logged your comments in our database and we will look into it and get back to you asap.

The comment has been logged against the issue id: CELLSJAVA-40177

Hi,

Would you please try following code to check whether the access to files can work:

Java


for(File ff : new File("/tmp/Fonts").listFiles())

{

byte[] data = new byte[(int)ff.length()];

RandomAccessFile raf = new RandomAccessFile(ff.getAbsolutePath(), “r”);

raf.seek(data.length/2);

raf.read(data, 0, data.length/2);

raf.seek(0);

raf.read(data, 0, data.length/2);

raf.close();

}

mshakeel.faiz:
Hi,

Would you please try following code to check whether the access to files can work:

Java
for(File ff : new File("/tmp/Fonts").listFiles())
{
byte[] data = new byte[(int)ff.length()];
RandomAccessFile raf = new RandomAccessFile(ff.getAbsolutePath(), "r");
raf.seek(data.length/2);
raf.read(data, 0, data.length/2);
raf.seek(0);
raf.read(data, 0, data.length/2);
raf.close();
}


it worked fine, no errors

Hi,

We have built a debug version to print some details of the process(by System.out.println()) and hope that can help us to figure the issue out. Please use this debug version to run your application and send us back the output. Thank you.

So I have to run my class from a command line and copy the output?

Hi,

Did you test whether you can reproduce such kind of issue by running your program from command line? If you can reproduce this issue at command line, it will be easier than in oracle environment for you and us to trace the issue. If the issue cannot be reproduced by command line, we are afraid we need a way to check the debug messages when you run your application in oracle environment(Hope you can find a way to dump the output of System.out, otherwise maybe we need to change the debug code to save the debug messages into a file of your local file system).