1 19 20 package org.netbeans.modules.j2ee.common.source; 21 22 import java.io.ByteArrayInputStream ; 23 import java.io.EOFException ; 24 import java.io.IOException ; 25 import java.io.InputStream ; 26 import java.io.OutputStream ; 27 import org.openide.filesystems.FileObject; 28 import org.openide.filesystems.FileUtil; 29 30 36 public class TestUtilities { 37 38 private TestUtilities() { 39 } 40 41 public static final FileObject copyStringToFileObject(FileObject fo, String content) throws IOException { 42 OutputStream os = fo.getOutputStream(); 43 try { 44 InputStream is = new ByteArrayInputStream (content.getBytes("UTF-8")); 45 FileUtil.copy(is, os); 46 return fo; 47 } finally { 48 os.close(); 49 } 50 } 51 52 public static final String copyFileObjectToString (FileObject fo) throws java.io.IOException { 53 int s = (int)FileUtil.toFile(fo).length(); 54 byte[] data = new byte[s]; 55 InputStream stream = fo.getInputStream(); 56 try { 57 int len = stream.read(data); 58 if (len != s) { 59 throw new EOFException ("truncated file"); 60 } 61 return new String (data); 62 } finally { 63 stream.close(); 64 } 65 } 66 } 67 | Popular Tags |