1cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath/* 2cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Licensed to the Apache Software Foundation (ASF) under one or more 3cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * contributor license agreements. See the NOTICE file distributed with 4cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * this work for additional information regarding copyright ownership. 5cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * The ASF licenses this file to You under the Apache License, Version 2.0 6cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * (the "License"); you may not use this file except in compliance with 7cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * the License. You may obtain a copy of the License at 8cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 9cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * http://www.apache.org/licenses/LICENSE-2.0 10cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * 11cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * Unless required by applicable law or agreed to in writing, software 12cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * License for the specific language governing permissions and limitations under 15cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * the License. 16cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 17cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 18ab762bb740405d0fefcccf4a0899a234f995be13Narayan Kamathpackage org.apache.harmony.tests.java.io; 19cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 20cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.File; 21cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.FileDescriptor; 22cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.FileInputStream; 23cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.FileNotFoundException; 24cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.FileOutputStream; 25cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport java.io.IOException; 26b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamathimport java.nio.ByteBuffer; 27b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamathimport java.nio.channels.FileChannel; 28cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 29cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathimport junit.framework.TestCase; 30cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 31cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamathpublic class FileOutputStreamTest extends TestCase { 32cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 332b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath private FileOutputStream fos; 342b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath private FileInputStream fis; 352b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath private File f; 362b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath private byte[] bytes; 37cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 38cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public String fileString = "Test_All_Tests\nTest_java_io_BufferedInputStream\nTest_java_io_BufferedOutputStream\nTest_java_io_ByteArrayInputStream\nTest_java_io_ByteArrayOutputStream\nTest_java_io_DataInputStream\nTest_java_io_File\nTest_java_io_FileDescriptor\nTest_java_io_FileInputStream\nTest_java_io_FileNotFoundException\nTest_FileOutputStream\nTest_java_io_FilterInputStream\nTest_java_io_FilterOutputStream\nTest_java_io_InputStream\nTest_java_io_IOException\nTest_java_io_OutputStream\nTest_java_io_PrintStream\nTest_java_io_RandomAccessFile\nTest_java_io_SyncFailedException\nTest_java_lang_AbstractMethodError\nTest_java_lang_ArithmeticException\nTest_java_lang_ArrayIndexOutOfBoundsException\nTest_java_lang_ArrayStoreException\nTest_java_lang_Boolean\nTest_java_lang_Byte\nTest_java_lang_Character\nTest_java_lang_Class\nTest_java_lang_ClassCastException\nTest_java_lang_ClassCircularityError\nTest_java_lang_ClassFormatError\nTest_java_lang_ClassLoader\nTest_java_lang_ClassNotFoundException\nTest_java_lang_CloneNotSupportedException\nTest_java_lang_Double\nTest_java_lang_Error\nTest_java_lang_Exception\nTest_java_lang_ExceptionInInitializerError\nTest_java_lang_Float\nTest_java_lang_IllegalAccessError\nTest_java_lang_IllegalAccessException\nTest_java_lang_IllegalArgumentException\nTest_java_lang_IllegalMonitorStateException\nTest_java_lang_IllegalThreadStateException\nTest_java_lang_IncompatibleClassChangeError\nTest_java_lang_IndexOutOfBoundsException\nTest_java_lang_InstantiationError\nTest_java_lang_InstantiationException\nTest_java_lang_Integer\nTest_java_lang_InternalError\nTest_java_lang_InterruptedException\nTest_java_lang_LinkageError\nTest_java_lang_Long\nTest_java_lang_Math\nTest_java_lang_NegativeArraySizeException\nTest_java_lang_NoClassDefFoundError\nTest_java_lang_NoSuchFieldError\nTest_java_lang_NoSuchMethodError\nTest_java_lang_NullPointerException\nTest_java_lang_Number\nTest_java_lang_NumberFormatException\nTest_java_lang_Object\nTest_java_lang_OutOfMemoryError\nTest_java_lang_RuntimeException\nTest_java_lang_SecurityManager\nTest_java_lang_Short\nTest_java_lang_StackOverflowError\nTest_java_lang_String\nTest_java_lang_StringBuffer\nTest_java_lang_StringIndexOutOfBoundsException\nTest_java_lang_System\nTest_java_lang_Thread\nTest_java_lang_ThreadDeath\nTest_java_lang_ThreadGroup\nTest_java_lang_Throwable\nTest_java_lang_UnknownError\nTest_java_lang_UnsatisfiedLinkError\nTest_java_lang_VerifyError\nTest_java_lang_VirtualMachineError\nTest_java_lang_vm_Image\nTest_java_lang_vm_MemorySegment\nTest_java_lang_vm_ROMStoreException\nTest_java_lang_vm_VM\nTest_java_lang_Void\nTest_java_net_BindException\nTest_java_net_ConnectException\nTest_java_net_DatagramPacket\nTest_java_net_DatagramSocket\nTest_java_net_DatagramSocketImpl\nTest_java_net_InetAddress\nTest_java_net_NoRouteToHostException\nTest_java_net_PlainDatagramSocketImpl\nTest_java_net_PlainSocketImpl\nTest_java_net_Socket\nTest_java_net_SocketException\nTest_java_net_SocketImpl\nTest_java_net_SocketInputStream\nTest_java_net_SocketOutputStream\nTest_java_net_UnknownHostException\nTest_java_util_ArrayEnumerator\nTest_java_util_Date\nTest_java_util_EventObject\nTest_java_util_HashEnumerator\nTest_java_util_Hashtable\nTest_java_util_Properties\nTest_java_util_ResourceBundle\nTest_java_util_tm\nTest_java_util_Vector\n"; 39cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 402b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath protected void setUp() { 412b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath bytes = new byte[10]; 422b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath for (int i = 0; i < bytes.length; i++) { 432b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath bytes[i] = (byte) i; 442b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath } 452b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath } 462b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath 472b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath /** 482b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath * Tears down the fixture, for example, close a network connection. This 492b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath * method is called after a test is executed. 502b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath */ 512b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath @Override 522b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath protected void tearDown() throws Exception { 532b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath super.tearDown(); 542b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath if (f != null) { 552b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f.delete(); 562b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath } 572b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath if (fis != null) { 582b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath fis.close(); 592b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath } 602b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath if (fos != null) { 612b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath fos.close(); 622b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath } 632b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath } 64cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 65cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 66cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#FileOutputStream(java.io.File) 67cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 68cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLjava_io_File() throws IOException { 692b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 70cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f); 71cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 72cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 73cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 74cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#FileOutputStream(java.io.FileDescriptor) 75cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 76cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLjava_io_FileDescriptor() throws IOException { 772b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 782b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath String fileName = f.getAbsolutePath(); 79cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(fileName); 80cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write('l'); 81cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 82cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis = new FileInputStream(fileName); 83cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(fis.getFD()); 84cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 85cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis.close(); 86cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 87cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 88cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 89cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#FileOutputStream(java.lang.String) 90cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 91cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLjava_lang_String() throws IOException { 922b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 932b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath String fileName = f.getAbsolutePath(); 94cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(fileName); 95cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 96e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath // Harmony 4012. 97e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath fos = new FileOutputStream("/dev/null"); 98e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath fos.close(); 99cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 100cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 101cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 102cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#FileOutputStream(java.lang.String, 103cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath *boolean) 104cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 105cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLjava_lang_StringZ() throws IOException { 1062b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 107cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f.getPath(), false); 108cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write("HI".getBytes(), 0, 2); 109cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 110cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f.getPath(), true); 111cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(fileString.getBytes()); 112cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 113cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath byte[] buf = new byte[fileString.length() + 2]; 114cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis = new FileInputStream(f.getPath()); 115cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis.read(buf, 0, buf.length); 116cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Failed to create appending stream", new String(buf, 0, 117cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath buf.length).equals("HI" + fileString)); 118cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 119cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 120cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 121cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#FileOutputStream(java.lang.String) 122cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 123cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_ConstructorLjava_lang_String_I() throws IOException { 124cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 125cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(""); 126cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("should throw FileNotFoundException."); 127cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (FileNotFoundException e) { 128cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 129cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } finally { 130cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (fos != null) { 131cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 132cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 133cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 134cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 135cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(new File("")); 136cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("should throw FileNotFoundException."); 137cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (FileNotFoundException e) { 138cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 139cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } finally { 140cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath if (fos != null) { 141cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 142cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 143cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 144cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 145cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 146cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 147cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#close() 148cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 149cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_close() throws IOException { 1502b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 151cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f.getPath()); 152cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 153cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 154cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 155cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(fileString.getBytes()); 156cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("Close test failed - wrote to closed stream"); 157cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IOException e) { 158cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 159cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 160cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 161cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 162cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 163cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#getFD() 164cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 165cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getFD() throws IOException { 1662b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 1672b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath String fileName = f.getAbsolutePath(); 168cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f); 169cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned invalid fd", fos.getFD().valid()); 170cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 171cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Returned invalid fd", !fos.getFD().valid()); 172cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 173cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 174cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 175cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#write(byte[]) 176cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 177cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_write$B() throws IOException { 1782b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 179cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f.getPath()); 180cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(fileString.getBytes()); 181cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis = new FileInputStream(f.getPath()); 182cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath byte rbytes[] = new byte[4000]; 183cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis.read(rbytes, 0, fileString.length()); 184cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect string returned", new String(rbytes, 0, 185cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fileString.length()).equals(fileString)); 186cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 187cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 188cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 189cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#write(byte[], int, int) 190cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 191cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_write$BII() throws IOException { 1922b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 193cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f.getPath()); 194cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(fileString.getBytes(), 0, fileString.length()); 195cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis = new FileInputStream(f.getPath()); 196cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath byte rbytes[] = new byte[4000]; 197cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis.read(rbytes, 0, fileString.length()); 198cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertTrue("Incorrect bytes written", new String(rbytes, 0, fileString 199cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath .length()).equals(fileString)); 200cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 201cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Regression test for HARMONY-285 202e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath File file = File.createTempFile("FileOutputStreamTest", ".tmp"); 203cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream out = new FileOutputStream(file); 204cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 205cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath out.write(null, 0, 0); 206e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath fail(); 207e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath } catch (NullPointerException expected) { 208e10c61bb13373b95ba857cc3af60f94b9941ab9eNarayan Kamath 209cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } finally { 210cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath out.close(); 211cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath file.delete(); 212cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 213cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 214cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 215cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 216cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#write(int) 217cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 218cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_writeI() throws IOException { 2192b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 220cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f.getPath()); 221cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write('t'); 222cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fis = new FileInputStream(f.getPath()); 223cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals("Incorrect char written", 't', fis.read()); 224cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 225cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 226cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 227cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#write(byte[], int, int) 228cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 229cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_write$BII2() throws IOException { 230cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Regression for HARMONY-437 2312b7c83942a5e28c53698232182193d5118028e6cNarayan Kamath f = File.createTempFile("FileOutputStreamTest", "tst"); 232cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(f.getPath()); 233cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 234cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 235cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(null, 1, 1); 236cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("NullPointerException must be thrown"); 237cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (NullPointerException e) { 238cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 239cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 240cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 241cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(new byte[1], -1, 1); 242cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("IndexOutOfBoundsException must be thrown if off <0"); 243cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IndexOutOfBoundsException e) { 244cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 245cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 246cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 247cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(new byte[1], 0, -1); 248cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("IndexOutOfBoundsException must be thrown if len <0"); 249cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IndexOutOfBoundsException e) { 250cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 251cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 252cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 253cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(new byte[1], 0, 5); 254cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("IndexOutOfBoundsException must be thrown if off+len > b.length"); 255cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IndexOutOfBoundsException e) { 256cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 257cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 258cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 259cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(new byte[10], Integer.MAX_VALUE, 5); 260cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("IndexOutOfBoundsException expected"); 261cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IndexOutOfBoundsException e) { 262cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 263cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 264cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 265cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(new byte[10], 5, Integer.MAX_VALUE); 266cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("IndexOutOfBoundsException expected"); 267cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (IndexOutOfBoundsException e) { 268cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 269cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 270cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 271cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 272cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 273cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#write(byte[], int, int) 274cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 275cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_write$BII3() throws IOException { 276cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Regression for HARMONY-834 277cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // no exception expected 278cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath new FileOutputStream(new FileDescriptor()).write(new byte[1], 0, 0); 279cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 280cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 281cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath /** 282cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath * java.io.FileOutputStream#getChannel() 283cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath */ 284cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getChannel() throws IOException { 285cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Regression for HARMONY-508 286cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath File tmpfile = File.createTempFile("FileOutputStream", "tmp"); 287cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath tmpfile.deleteOnExit(); 288cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream fos = new FileOutputStream(tmpfile); 289cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 290cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.flush(); 291cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 292cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream f = new FileOutputStream(tmpfile, true); 293b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamath assertEquals(10, f.getChannel().position()); 294cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 295cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 296cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getChannel_Append() throws IOException { 297cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath File tmpfile = File.createTempFile("FileOutputStream", "tmp"); 298cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath tmpfile.deleteOnExit(); 299cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream fos = new FileOutputStream(tmpfile, true); 300cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 301cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 302cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(10, fos.getChannel().position()); 303cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 304cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(20, fos.getChannel().position()); 305cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 306cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(30, fos.getChannel().position()); 307cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 308cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 309cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 310cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.getChannel().position(); 311cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("should throw ClosedChannelException"); 312cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (java.nio.channels.ClosedChannelException e) { 313cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 314cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 315cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 316cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 317cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getChannel_UnAppend() throws IOException { 318cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath File tmpfile = File.createTempFile("FileOutputStream", "tmp"); 319cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath tmpfile.deleteOnExit(); 320cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream fos = new FileOutputStream(tmpfile, false); 321cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 322cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 323cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(10, fos.getChannel().position()); 324cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 325cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(20, fos.getChannel().position()); 326cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 327cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(30, fos.getChannel().position()); 328cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 329cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 330cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath try { 331cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.getChannel().position(); 332cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fail("should throw ClosedChannelException"); 333cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } catch (java.nio.channels.ClosedChannelException e) { 334cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath // Expected 335cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 336cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 337cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 338cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getChannel_Unappend_Unappend() throws IOException { 339cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath File tmpfile = File.createTempFile("FileOutputStream", "tmp"); 340cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath tmpfile.deleteOnExit(); 341cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream fos = new FileOutputStream(tmpfile, false); 342cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 343cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 344cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(10, fos.getChannel().position()); 345cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 346cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 347cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(tmpfile, false); 348cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 349cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 350cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 351cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 352cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getChannel_Unappend_Append() throws IOException { 353cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath File tmpfile = File.createTempFile("FileOutputStream", "tmp"); 354cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath tmpfile.deleteOnExit(); 355cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream fos = new FileOutputStream(tmpfile, false); 356cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 357cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 358cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(10, fos.getChannel().position()); 359cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 360cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 361cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(tmpfile, true); 362b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamath assertEquals(10, fos.getChannel().position()); 363cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 364cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 365cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 366cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getChannel_Append_Unappend() throws IOException { 367cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath File tmpfile = File.createTempFile("FileOutputStream", "tmp"); 368cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath tmpfile.deleteOnExit(); 369cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream fos = new FileOutputStream(tmpfile, true); 370cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 371cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 372cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(10, fos.getChannel().position()); 373cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 374cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 375cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(tmpfile, false); 376cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 377cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 378cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 379cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 380cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath public void test_getChanne_Append_Append() throws IOException { 381cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath File tmpfile = File.createTempFile("FileOutputStream", "tmp"); 382cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath tmpfile.deleteOnExit(); 383cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath FileOutputStream fos = new FileOutputStream(tmpfile, true); 384cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(0, fos.getChannel().position()); 385cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.write(bytes); 386cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath assertEquals(10, fos.getChannel().position()); 387cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 388cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath 389cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos = new FileOutputStream(tmpfile, true); 390b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamath FileChannel fc = fos.getChannel(); 391b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamath assertEquals(10, fc.position()); 392b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamath fc.write(ByteBuffer.wrap("hello".getBytes(java.nio.charset.StandardCharsets.UTF_8))); 393b7b2b8be079b63a1473e25580eefa1566e69be1dNarayan Kamath assertEquals(15, fc.position()); 394cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath fos.close(); 395cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath } 396cb318c6f4fe5b0e20099fa85f1b95ccb2d24119fNarayan Kamath} 397