1 19 20 package org.netbeans.modules.tasklist.providers; 21 22 import org.openide.filesystems.FileObject; 23 import org.openide.ErrorManager; 24 25 import java.io.*; 26 27 32 final class XMLSuggestionContext { 33 34 static String getContent(FileObject fo) { 35 try { 36 char[] buf = new char[1024*64]; 37 StringBuffer sb = new StringBuffer (); 38 InputStream input = new BufferedInputStream(fo.getInputStream(), 2157); 39 String encoding = null; 40 try { 41 encoding = XMLEncodingHelper.detectEncoding(input); 42 } finally { 43 try { 44 input.close(); 45 } catch (IOException ex) { 46 } 48 } 49 if (encoding == null) return null; 50 51 Reader r = new InputStreamReader(new BufferedInputStream(fo.getInputStream()), encoding); 52 try { 53 int len; 54 while (true) { 55 len = r.read(buf); 56 if (len == -1) break; 57 sb.append(buf, 0, len); 58 } 59 return sb.toString(); 60 } finally { 61 r.close(); 62 } 63 } catch (IOException e) { 64 ErrorManager.getDefault().notify(e); 65 } 66 return null; 67 } 68 69 } 70 | Popular Tags |