0

I am using outputstreamwriter to write the output of resultset of some report to csv file.But the csv file has only 100k lines which should be some 600k lines.Was the data truncated while writing to csv after 100k lines?.I am not able to figure out what could be the issue.Googling didint provide me any solution.

Does Using printwriter to get all the 600k lines makes sense.

reportData = reportSession.generateAdvancedReport( id, format, displayType, request.getRequestedSessionId(), 0, 0, false,
                     report.getIsDashboardComponent() && report.getDisplayPregeneratedData(), testContextObjectId, testContextObjectName, testContextObjectProp1 );

if( reportData != null )
         {
            for( int i = 0; i < reportData.size(); i ++)
            {
                if( i != 0 )
                    writer.write( "\n" );
                for( int j = 0; j < reportData.get( i ).size(); j++ )
                {
                    writer.write( "\"" );
                    /*
                     * Mantis ID 4468
                     * null check added as it was throwing illegal state exception 
                     */
                    if(reportData.get( i ).get( j ) != null)
                        writer.write( reportData.get( i ).get( j ) );
                    else
                        writer.write( "" );
                    writer.write( "\"" );
                    if( j != reportData.get( i ).size() - 1 )
                        writer.write( "," );
                }
            }
         }
gknicker
  • 5,509
  • 2
  • 25
  • 41
user3607869
  • 317
  • 1
  • 9
  • 19

2 Answers2

0

Was the data truncated while writing to csv after 100k lines?

Probably not (IMO). Certainly using a PrintWriter versus an OutputStreamWriter won't make any difference.

It is possible that truncation occurred because you didn't close() the output file (and hence, buffered data was lost), but it is also possible that the supposed "truncation" is actually happening because the report contains less data than you expect.

Hint: look at the end of the supposedly truncated file. Does it look like it has been truncated? Is the last character a double-quote?

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216
0

Yes, using PrintWriter to get all 600k lines makes perfect sense.

Most likely you're looking at the output in Windows using a text viewer/editor that doesn't recognize the *nix line endings "\n" (newline only). If you want your csv file to behave correctly in Windows, change that to the Windows line ending "\r\n" (carriage return and line feed).

if( i != 0 )
    writer.write( "\r\n" );
gknicker
  • 5,509
  • 2
  • 25
  • 41