public inbox for java-prs@sourceware.org
help / color / mirror / Atom feed
* [Bug java/18376] New:  java.io.BufferedWriter outputing  extraneous characters?
@ 2004-11-08 14:57 wayne dot gray at coynetextileservices dot com
  2004-11-08 15:00 ` [Bug libgcj/18376] " pinskia at gcc dot gnu dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: wayne dot gray at coynetextileservices dot com @ 2004-11-08 14:57 UTC (permalink / raw)
  To: java-prs

Version:  gcj 3.4.0 20040316 on Windows 2000 (mingw)

The below copy file function works in Sun's 1.4.1_01 JVM but with GCJ the output
has tons of whitespace added.

I have a complete test set up but am unsure how to attach files to this report.
 If you need more info then please give me instructions on how to get them to
you. Thanks.

package TestGcj;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;


public class IoTest {

	/**
	 * 
	 */
	public IoTest() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	public static void main(String[] args){
		try 
		{
			copyFile2(args[0], args[1]);
		} catch (Exception e){
			e.printStackTrace();
		}
	}
	
	public static void copyFile2(String src, String dest) throws IOException{
		String newLine = System.getProperty("line.separator"); 
		FileWriter fw = null; 
		FileReader fr = null; 
		BufferedReader br = null; 
		BufferedWriter bw = null; 
		File source = null; 

 
		try { 
		fr = new FileReader(src); 
		fw = new FileWriter(dest); 
		br = new BufferedReader(fr); 
		bw = new BufferedWriter(fw); 

		/* Determine the size of the buffer to allocate */ 
		source = new File(src); 

		int fileLength = (int) source.length(); 

		char charBuff[] = new char[fileLength]; 

		while (br.read(charBuff,0,fileLength) != -1) 
		bw.write(charBuff,0,fileLength); 
		  } 
		catch(FileNotFoundException fnfe){ 
			System.out.println(src + " does not exist!");
			return;
		} 
		catch(IOException ioe) { 
			System.out.println("Error reading/writing files!");
			return;
		} 
		finally { 
			try { 
				if (br != null) 
				br.close(); 

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

}

Build Output:

Buildfile: build.xml

build:
    [mkdir] Created dir: C:\TEMP\jtracetest\TestGcj\out
     [copy] Copied 1 empty directory to 1 empty directory under
C:\TEMP\jtracetest\TestGcj\out
    [apply] Reading specs from C:/gcc-3.4/bin/../lib/gcc/i686-pc-mingw32/3.4.0/specs
    [apply] Reading specs from
C:/gcc-3.4/bin/../lib/gcc/i686-pc-mingw32/3.4.0/../../../../i686-pc-mingw32/lib/libgcj.spec
    [apply] rename spec lib to liborig
    [apply] Configured with: /datal/gcc/gcc/configure
--prefix=/datal/gcc/build/wingcc --build=i686-pc-linux-gnu
--host=i686-pc-mingw32 --target=i686-pc-mingw32 --enable-languages=c,c++,java
--with-gcc --with-gnu-as --with-gnu-ld --with-as=i686-pc-mingw32-as
--with-ld=i686-pc-mingw32-ld --enable-threads=win32 --disable-nls
--disable-win32-registry --disable-shared --disable-debug --without-newlib
--enable-libgcj --disable-java-awt --without-x --enable-java-gc=boehm
--disable-libgcj-debug --enable-interpreter --enable-hash-synchronization
--enable-sjlj-exceptions --enable-libgcj-multifile --enable-libgcj-mingw-osapi=ansi
    [apply] Thread model: win32
    [apply] gcc version 3.4.0 20040316 (prerelease)
    [apply]  C:/gcc-3.4/bin/../libexec/gcc/i686-pc-mingw32/3.4.0/jc1.exe
C:\TEMP\jtracetest\TestGcj\src\TestGcj\IoTest.java -fhash-synchronization
-fuse-divide-subroutine -fcheck-references -fuse-boehm-gc -fnon-call-exceptions
-fkeep-inline-functions -quiet -dumpbase IoTest.java -mtune=pentiumpro
-auxbase-strip C:\TEMP\jtracetest\TestGcj\out\TestGcj\IoTest.o -g -O -Wall
-version -fCLASSPATH=C:\TEMP\jtracetest\TestGcj/src/ -o
C:\DOCUME~1\WGGRAY\LOCALS~1\Temp/ccCwaaaa.s
    [apply] GNU Java version 3.4.0 20040316 (prerelease) (i686-pc-mingw32)
    [apply] 	compiled by GNU C version 3.4.0 20040316 (prerelease).
    [apply] GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=65279
    [apply] Class path starts here:
    [apply]     C:\TEMP\jtracetest\TestGcj/src/
    [apply]     C:\gcc-3.4\bin/../lib/gcc/../../share/java/libgcj-3.4.0.jar/
(system) (zip)
    [apply] 
C:/gcc-3.4/bin/../lib/gcc/i686-pc-mingw32/3.4.0/../../../../i686-pc-mingw32/bin/as.exe
-o C:\TEMP\jtracetest\TestGcj\out\TestGcj\IoTest.o
C:\DOCUME~1\WGGRAY\LOCALS~1\Temp/ccCwaaaa.s



link:



BUILD SUCCESSFUL
Total time: 2 seconds

-- 
           Summary:  java.io.BufferedWriter outputing  extraneous
                    characters?
           Product: gcc
           Version: 3.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: java
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: wayne dot gray at coynetextileservices dot com
                CC: gcc-bugs at gcc dot gnu dot org,java-prs at gcc dot gnu
                    dot org


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
@ 2004-11-08 15:00 ` pinskia at gcc dot gnu dot org
  2004-11-08 15:02 ` wayne dot gray at coynetextileservices dot com
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-08 15:00 UTC (permalink / raw)
  To: java-prs



-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|java                        |libgcj
            Summary| java.io.BufferedWriter     |java.io.BufferedWriter
                   |outputing  extraneous       |outputing  extraneous
                   |characters?                 |characters?


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
  2004-11-08 15:00 ` [Bug libgcj/18376] " pinskia at gcc dot gnu dot org
@ 2004-11-08 15:02 ` wayne dot gray at coynetextileservices dot com
  2004-11-08 18:34 ` pinskia at gcc dot gnu dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: wayne dot gray at coynetextileservices dot com @ 2004-11-08 15:02 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From wayne dot gray at coynetextileservices dot com  2004-11-08 15:02 -------
Created an attachment (id=7492)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=7492&action=view)
Java class, build script, and example output in demo directory

This is a demo of the function.  In the demo directory file buildlog.txt is the
source file and file buildlogcopy.txt is the resulting file.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
  2004-11-08 15:00 ` [Bug libgcj/18376] " pinskia at gcc dot gnu dot org
  2004-11-08 15:02 ` wayne dot gray at coynetextileservices dot com
@ 2004-11-08 18:34 ` pinskia at gcc dot gnu dot org
  2004-11-08 22:17 ` tromey at gcc dot gnu dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-11-08 18:34 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From pinskia at gcc dot gnu dot org  2004-11-08 18:34 -------
Confirmed on the mainline, I don't know what is going on but we are writting out zeros.

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|                            |1
   Last reconfirmed|0000-00-00 00:00:00         |2004-11-08 18:34:31
               date|                            |


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
                   ` (2 preceding siblings ...)
  2004-11-08 18:34 ` pinskia at gcc dot gnu dot org
@ 2004-11-08 22:17 ` tromey at gcc dot gnu dot org
  2004-11-09 13:37 ` wayne dot gray at coynetextileservices dot com
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: tromey at gcc dot gnu dot org @ 2004-11-08 22:17 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2004-11-08 22:17 -------
The code says:

  while (br.read(charBuff,0,fileLength) != -1) 
    bw.write(charBuff,0,fileLength); 

There is no guarantee that read() will fill the buffer.
If you see a partial read, you will then write a full buffer,
meaning that the remainder of the buffer will be zero
(or leftovers from an earlier read).

So, I think this is not a libgcj bug.


-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
                   ` (3 preceding siblings ...)
  2004-11-08 22:17 ` tromey at gcc dot gnu dot org
@ 2004-11-09 13:37 ` wayne dot gray at coynetextileservices dot com
  2004-11-09 22:11 ` tromey at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: wayne dot gray at coynetextileservices dot com @ 2004-11-09 13:37 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From wayne dot gray at coynetextileservices dot com  2004-11-09 13:36 -------
(In reply to comment #3)
> The code says:
> 
>   while (br.read(charBuff,0,fileLength) != -1) 
>     bw.write(charBuff,0,fileLength); 
> 
> There is no guarantee that read() will fill the buffer.
> If you see a partial read, you will then write a full buffer,
> meaning that the remainder of the buffer will be zero
> (or leftovers from an earlier read).
> 
> So, I think this is not a libgcj bug.
> 

I see what you're saying.  But if that were true then the while loop would have
multiple iterations.  No?

The read and write methods are only being called once in this method for this
file.  Just confirmed with another test.

This is true because I'm sizing the buffer to the length of the file and... 

  br.read(charBuff,0,fileLength)

...reads the entire file length in the first shot.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
                   ` (4 preceding siblings ...)
  2004-11-09 13:37 ` wayne dot gray at coynetextileservices dot com
@ 2004-11-09 22:11 ` tromey at gcc dot gnu dot org
  2004-11-10 18:23 ` wayne dot gray at coynetextileservices dot com
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: tromey at gcc dot gnu dot org @ 2004-11-09 22:11 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From tromey at gcc dot gnu dot org  2004-11-09 22:11 -------
I downloaded the test case and modified it to print the
number of characters it read.  I can confirm that for me it
does in fact loop:

opsy. gij TestGcj.IoTest ../demo/buildlog.txt  Out.txt
fileLength = 2290
x = 2048
x = 242

A few things to note here.

First, you're using a BufferedReader, so you aren't guaranteed
to fill your request array.  You might pick up buffered data instead.

Second, using characters here is incorrect, as File.length() returns
the size in bytes.  This seems to be the cause of the problem we're
seeing with the test case, since it still operates in the same way
if I remove the buffering.  I think the internal character set converters
have their own buffers and as a result we don't get a full file read.

If I change the loop in this test program to use the actual read result
as the length argument to write, it works properly.  So, even though libgcj
is perhaps a little odd here, I still think it is correct.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
                   ` (5 preceding siblings ...)
  2004-11-09 22:11 ` tromey at gcc dot gnu dot org
@ 2004-11-10 18:23 ` wayne dot gray at coynetextileservices dot com
  2005-04-28 21:52 ` pinskia at gcc dot gnu dot org
  2005-04-28 22:38 ` greenrd at greenrd dot org
  8 siblings, 0 replies; 10+ messages in thread
From: wayne dot gray at coynetextileservices dot com @ 2004-11-10 18:23 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From wayne dot gray at coynetextileservices dot com  2004-11-10 18:23 -------
Ok thanks.  I'll rip out that File.length() stuff and see if that works.

Thanks for your time.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
                   ` (6 preceding siblings ...)
  2004-11-10 18:23 ` wayne dot gray at coynetextileservices dot com
@ 2005-04-28 21:52 ` pinskia at gcc dot gnu dot org
  2005-04-28 22:38 ` greenrd at greenrd dot org
  8 siblings, 0 replies; 10+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-04-28 21:52 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-04-28 21:52 -------
*** Bug 21270 has been marked as a duplicate of this bug. ***

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |mnefedov at rogers dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

* [Bug libgcj/18376] java.io.BufferedWriter outputing  extraneous characters?
  2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
                   ` (7 preceding siblings ...)
  2005-04-28 21:52 ` pinskia at gcc dot gnu dot org
@ 2005-04-28 22:38 ` greenrd at greenrd dot org
  8 siblings, 0 replies; 10+ messages in thread
From: greenrd at greenrd dot org @ 2005-04-28 22:38 UTC (permalink / raw)
  To: java-prs


------- Additional Comments From greenrd at greenrd dot org  2005-04-28 22:38 -------
Please reopen. JDK1.5 javadocs for BufferedReader.read include this new information:

"As an additional convenience, it attempts to read as many characters as
possible by repeatedly invoking the read method of the underlying stream."

Bug 18840 addressed the same issue for BufferedInputStream by bringing libgcj
into compliance with JDK1.5; the same should be done here, for BufferedReader.

-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18376


^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2005-04-28 22:38 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-11-08 14:57 [Bug java/18376] New: java.io.BufferedWriter outputing extraneous characters? wayne dot gray at coynetextileservices dot com
2004-11-08 15:00 ` [Bug libgcj/18376] " pinskia at gcc dot gnu dot org
2004-11-08 15:02 ` wayne dot gray at coynetextileservices dot com
2004-11-08 18:34 ` pinskia at gcc dot gnu dot org
2004-11-08 22:17 ` tromey at gcc dot gnu dot org
2004-11-09 13:37 ` wayne dot gray at coynetextileservices dot com
2004-11-09 22:11 ` tromey at gcc dot gnu dot org
2004-11-10 18:23 ` wayne dot gray at coynetextileservices dot com
2005-04-28 21:52 ` pinskia at gcc dot gnu dot org
2005-04-28 22:38 ` greenrd at greenrd dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).