Operating System - OpenVMS
1828355 Members
3017 Online
109976 Solutions
New Discussion

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

 
quinnd6
Occasional Advisor

BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

I was using this version of java and Fast VM (build 1.4.1-2, build J2SDK.v.1.4.1 on OpenVMS. I wrote a program which appends strings to a string buffer.
It then converts the string buffer to a string and outputs that to a file using bufferedwriter.write
However it causes line breaks in the file where it shouldn't and I dont know why.

Are there any known issues with bufferedwriter in this java version?

What could be causing these fairly random line breaks?
Its also using Fast VM (build 1.4.1-2, build J2SDK.v.1.4.1.
Can Fast VM run in different modes that might cause this?
8 REPLIES 8
John Gillings
Honored Contributor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

quinnd6,

"fairly random"? Does this mean they're unrelated to the strings being appended?

What is the record format of your file? (DIR/FULL) Can you check the binary contents of the file around the apparent line breaks (use DUMP and compare with DUMP/RECORD). It may also be interesting to see the binary contents of your string buffer and again after it's been converted.
A crucible of informative mistakes
quinnd6
Occasional Advisor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

Ill show you my code and how it breaks.
Sometimes when I run it there are no bad line breaks and other times there would be one every 800 or so lines.

import java.util.*;

import java.util.*;
import java.io.*;
import java.io.BufferedWriter;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.io.IOException;
import java.io.Serializable;

import java.text.SimpleDateFormat;
import java.util.*;
class Test3 {

public static void main(String[] args) throws IOException {
String contents = "";
int lSize = 0;

FileWriter fw = new FileWriter("test10.txt");

BufferedWriter bw = null;
StringBuffer strb = new StringBuffer();


strb.append("allow_from");
strb.append(" ");
strb.append("dq@dq.com");
strb.append("\n");
String bufferString =strb.toString();
try {
bw = new BufferedWriter(fw);


// Now put together the contents of the file:
for(int i=1;i<60000;i++)
{

bw.write(i+ " "+bufferString);

}
catch(IOException ioe) {
throw ioe;
}
finally {
if(bw!=null) bw.close();
}




}

}

quinnd6
Occasional Advisor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

I changed the for loop to go from 1 to 5001 and then.
I tried running it on windows and then I sent the program and the text file I had been writing to on windows over to the open vms machine.

Then when I ran it on open vms there were the line breaks on line 988 and 1303, line 1618 etc. like this (note I havent put in all the lines cos it'd take up to0 much space)
987 allow_from dq@dq.com
988 allow
_from dq@dq.com
989 allow_from dq@dq.com

1301 allow_from dq@dq.com
1302 allow_from dq@dq.com
1303 allow_from dq@dq.c
om
1304 allow_from dq@dq.com
1305 allow_from dq@dq.com


1618 allow_from dq@dq.com

1619 allow_from dq@dq.com

1933 allow_from dq@dq.com
1
934 allow_from dq@dq.com
1935 allow_from dq@dq.com
1936 allow_from dq@dq.com

2248 allow_from dq@dq.com
224
9 allow_from dq@dq.com
2250 allow_from dq@dq.com

so it does that every 300 lines or so and all other lines seem ok.
It seems to be because I sent a text file over from windows to open vms and it got corrupted.



Bojan Nemec
Honored Contributor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

Hi,

First, welcome to the VMS forum.

I tested your program with a different version of java (Classic VM (build 1.5.0-3, 03/01/2007-14:39, native threads, jit) and Fast VM (build 1.5.0-3, build J2SDK.v.1.5.0:03/01/2007-21:16, native threads, ji
t_150)). I cant reproduce the error.

Was the test10.txt a new file or only a new version of an existing file? Java (read as C) keeps the attributes of the existing file.
Could you post the DIR/FULL output as John suggested.

A quick check to line breaks you posted gives me the numbers:
first break at character position 24576 (0x6000)
second break at character position 32768 (0x8000)

The second is intresting 32767 is the maximal record size for many sequential file formats.

Bojan
quinnd6
Occasional Advisor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

Im using a different file name now but it has the same problem

TEST13.TXT;1 File ID: (739634,8,0)
Size: 252/255 Owner: [900013A,DAVIDQUINN]
Created: 22-MAY-2007 09:53:19.89
Revised: 22-MAY-2007 09:53:25.64 (1)
Expires:
Backup:
Effective:
Recording:
Accessed:
Attributes:
Modified:
Linkcount: 1
File organization: Sequential
Shelved state: Online
Caching attribute: Writethrough
File attributes: Allocation: 255, Extend: 0, Global buffer count: 0, No version limit
Record format: Variable length, maximum 0 bytes, longest 32767 bytes
Record attributes: Carriage return carriage control
RMS attributes: None
Journaling enabled: None
File protection: System:RWED, Owner:RWED, Group:RE, World:
Access Cntrl List: None
Client attributes: None
Hein van den Heuvel
Honored Contributor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

I suspect with others that the program is writting the file as a long records with embedded new-lines, rather then many independent lines as intended.
However, that math does not work exacltly.
I would suggest that the line length of about 32, not the 26 shown.

To verify, check the output from $DUMP/RECORD=COUNT=1

You probably want to force a 'STREAM_LF' or STREAM output file. I don't know enough about the tools you used to help you force this. It could be a logical names, an open option, or the (non) presence of an existing file with the same name and the desired attributes.
To create such file, try:

$CREATE/FDL=SYS$INPUT:
RECORD; FORMAT STREAM_LF
$

What OpenVMS version?
It may be a problem which has been fixed?

Good luck,
Hein.
Bojan Nemec
Honored Contributor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

Hein was faster than me.

You can try also to force stream_lf with:

$ DEFINE JAVA$CREATE_STMLF_FORMAT TRUE

Bojan
quinnd6
Occasional Advisor

Re: BufferedWriter and Stringbuffer Issue- J2SDK.v.1.4.1

The open vms version is
OpenVMS Alpha V7.3-1