WriteBytesChars.java revision 2497
321N/A/*
321N/A * Copyright (c) 1997, Oracle and/or its affiliates. All rights reserved.
321N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
321N/A *
321N/A * This code is free software; you can redistribute it and/or modify it
178N/A * under the terms of the GNU General Public License version 2 only, as
178N/A * published by the Free Software Foundation.
178N/A *
224N/A * This code is distributed in the hope that it will be useful, but WITHOUT
295N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
295N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
295N/A * version 2 for more details (a copy is included in the LICENSE file that
178N/A * accompanied this code).
178N/A *
178N/A * You should have received a copy of the GNU General Public License version
178N/A * 2 along with this work; if not, write to the Free Software Foundation,
224N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
179N/A *
183N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
183N/A * or visit www.oracle.com if you need additional information or have any
183N/A * questions.
183N/A */
183N/A
366N/A/* @test
366N/A @bug 4074388
366N/A @summary Check for correct implementation of RandomAccessFile.writeBytes
366N/A and writeChars.
366N/A */
366N/A
366N/Aimport java.io.*;
366N/A
366N/Apublic class WriteBytesChars {
366N/A
366N/A public static void main(String args[]) throws Exception {
366N/A String towrite;
366N/A char[] buf = new char[80];
222N/A byte[] b = new byte[80];
222N/A File fn = new File("x.WriteBytesChars");
222N/A
222N/A RandomAccessFile raf = new RandomAccessFile(fn , "rw");;
222N/A try {
222N/A for (int i = 0; i < 80; i++) {
222N/A buf[i] = 'a';
222N/A }
222N/A towrite = new String(buf);
222N/A
222N/A raf.writeBytes(towrite);
222N/A raf.seek(0);
222N/A raf.read(b);
222N/A
222N/A System.out.println("RandomAccessFile.writeBytes");
222N/A if (towrite.equals(new String(b))) {
222N/A System.err.println("Test succeeded.");
222N/A } else {
222N/A throw new
222N/A RuntimeException("RandomAccessFile.writeBytes, wrong result");
222N/A }
222N/A
222N/A raf.seek(0);
222N/A raf.writeChars(towrite);
222N/A raf.seek(0);
222N/A for (int i = 0; i < 80; i++) {
222N/A buf[i] = raf.readChar();
222N/A }
366N/A
222N/A System.out.println("RandomAccessFile.writeChars");
222N/A if (towrite.equals(new String(buf))) {
222N/A System.err.println("Test succeeded.");
222N/A } else {
222N/A throw new
222N/A RuntimeException("RandomAccessFile.writeChars, wrong result");
222N/A }
222N/A } finally {
222N/A raf.close();
222N/A fn.delete();
222N/A }
222N/A }
222N/A}
222N/A