Path: blob/master/test/jdk/java/io/RandomAccessFile/WriteBytesChars.java
41149 views
/*1* Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/* @test24@bug 407438825@summary Check for correct implementation of RandomAccessFile.writeBytes26and writeChars.27*/2829import java.io.*;3031public class WriteBytesChars {3233public static void main(String args[]) throws Exception {34String towrite;35char[] buf = new char[80];36byte[] b = new byte[80];37File fn = new File("x.WriteBytesChars");3839RandomAccessFile raf = new RandomAccessFile(fn , "rw");;40try {41for (int i = 0; i < 80; i++) {42buf[i] = 'a';43}44towrite = new String(buf);4546raf.writeBytes(towrite);47raf.seek(0);48raf.read(b);4950System.out.println("RandomAccessFile.writeBytes");51if (towrite.equals(new String(b))) {52System.err.println("Test succeeded.");53} else {54throw new55RuntimeException("RandomAccessFile.writeBytes, wrong result");56}5758raf.seek(0);59raf.writeChars(towrite);60raf.seek(0);61for (int i = 0; i < 80; i++) {62buf[i] = raf.readChar();63}6465System.out.println("RandomAccessFile.writeChars");66if (towrite.equals(new String(buf))) {67System.err.println("Test succeeded.");68} else {69throw new70RuntimeException("RandomAccessFile.writeChars, wrong result");71}72} finally {73raf.close();74fn.delete();75}76}77}787980