public InputStream getInputStream( boolean isLocal ) { try { return _resourceFile.openInputStream(); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Reader getReader() { try { return StreamUtil.getInputStreamReader(_file.openInputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
@Override public Reader getReader() { try { return StreamUtil.getInputStreamReader(_file.openInputStream()); } catch (IOException e) { throw new RuntimeException(e); } }
private String readFileWithoutHandlingExceptions(IFile file) throws IOException { byte[] result = new byte[0]; InputStream inputStream = file.openInputStream(); try { byte[] buffer = new byte[4196]; while (true) { int numRead = inputStream.read(buffer); if (numRead != -1) { byte[] newResult = new byte[result.length + numRead]; System.arraycopy(result, 0, newResult, 0, result.length); System.arraycopy(buffer, 0, newResult, result.length, numRead); result = newResult; } else { break; } } } finally { inputStream.close(); } // TODO - AHK - Verify the charset somehow? return new String(result); } }
public ManifestVerifyUtil(IDirectory dir, String expectedVersion) { InputStream in = null; try { in = dir.file("META-INF/MANIFEST.MF").openInputStream(); _mf = new Manifest(in); } catch (IOException e) { throw new RuntimeException(e); } finally { try { StreamUtil.close(in); } catch (IOException e) { // ignore } } _expectedVersion = expectedVersion; }
public String getCachedContent() { if( _contentCached == null ) { IFile[] files = getSourceFiles(); if( files != null && files.length > 0 ) { try { InputStream inputStream = files[0].openInputStream(); _contentCached = StreamUtil.getContent( new InputStreamReader( inputStream ) ).replace( "\r\n", "\n" ); inputStream.close(); } catch( Exception e ) { throw new RuntimeException( e ); } } } return _contentCached; }
private String parseEnhancedTypeName(RefreshRequest request) { try { return parseEnhancedTypeName(request.file.openInputStream(), request.file.getBaseName()); } catch (IOException e) { return IErrorType.NAME; } }
@Override public ISource getSource() { try { return new StringSource( StreamUtil.getContent( StreamUtil.getInputStreamReader( _file.openInputStream() ) ) ); } catch( IOException e ) { throw new RuntimeException( e ); } }
private static List<Pair<String, String>> readTaskListingFromPropertiesFile(IFile resource) { InputStream in = null; try { in = resource.openInputStream(); if (in == null) { AntlibTypeLoader.log("Could not load definitions from " + resource, Project.MSG_WARN); } Properties tasks = new Properties(); tasks.load(in); List<Pair<String, String>> listing = new ArrayList<Pair<String, String>>(); for (Map.Entry<Object, Object> entry : tasks.entrySet()) { listing.add(new Pair<String, String>((String) entry.getKey(), (String) entry.getValue())); } return listing; } catch (IOException e) { throw GosuExceptionUtil.forceThrow(e); } finally { FileUtils.close(in); } }
protected boolean initAvailable( String path ) { final URL resource = getClass().getClassLoader().getResource( path ); if ( resource != null ) { try { // try { // return CommonServices.getFileSystem().getIFile(new File(url.toURI())); // } catch (URISyntaxException e) { // throw new RuntimeException(e); // } InputStream stream = CommonServices.getFileSystem().getIFile(resource).openInputStream(); readAvailable( stream ); return true; } catch ( Throwable e ) { throw new RuntimeException( "initAvailable from resource " + path, e ); } } File file = new File( path ); if ( file.exists() ) { try { readAvailable( new FileInputStream( file ) ); } catch ( Throwable e ) { throw new RuntimeException( "initAvailable from file system " + path, e ); } } return false; }
/** * Reads a pom.xml file into a GosuPathEntry object * * @param moduleFile the pom.xml file to convert to GosuPathEntry * @return an ordered list of GosuPathEntries created based on the algorithm described above */ public static GosuPathEntry createPathEntryForModuleFile(IFile moduleFile) { try { InputStream is = moduleFile.openInputStream(); try { SimpleXmlNode moduleNode = SimpleXmlNode.parse(is); IDirectory rootDir = moduleFile.getParent(); List<IDirectory> sourceDirs = new ArrayList<IDirectory>(); for (String child : new String[] { "gsrc", "gtest" }) { IDirectory dir = rootDir.dir(child); if (dir.exists()) { sourceDirs.add(dir); } } return new GosuPathEntry(rootDir, sourceDirs); } finally { is.close(); } } catch (IOException e) { throw new RuntimeException(e); } } }
/** * Reads a pom.xml file into a GosuPathEntry object * * @param moduleFile the pom.xml file to convert to GosuPathEntry * @return an ordered list of GosuPathEntries created based on the algorithm described above */ public static GosuPathEntry createPathEntryForModuleFile(IFile moduleFile) { try { InputStream is = moduleFile.openInputStream(); try { SimpleXmlNode moduleNode = SimpleXmlNode.parse(is); IDirectory rootDir = moduleFile.getParent(); List<IDirectory> sourceDirs = new ArrayList<IDirectory>(); for (String child : new String[] { "gsrc", "gtest" }) { IDirectory dir = rootDir.dir(child); if (dir.exists()) { sourceDirs.add(dir); } } return new GosuPathEntry(rootDir, sourceDirs); } finally { is.close(); } } catch (IOException e) { throw new RuntimeException(e); } } }
@Override public XmlElement parse( URL url, XmlParseOptions options ) { InputStream inputStream; String urlEF = url.toExternalForm(); try { // try { // return CommonServices.getFileSystem().getIFile(new File(url.toURI())); // } catch (URISyntaxException e) { // throw new RuntimeException(e); // } inputStream = CommonServices.getFileSystem().getIFile(url).openInputStream(); return parse( null, new InputSource( inputStream ), urlEF, getSchemaIndexes( options ), null, options, null, null ); } catch ( IOException ex ) { throw new XmlException( "Unable to parse file " + urlEF, ex ); } }
@Override public PropertySet getPropertySet(String name) { IFile file = _filesByTypeName.get().get(name); if (file == null) { throw new IllegalArgumentException(name + " is not the name of a properties file property set"); } PropertySet result = new EmptyPropertySet(name); if (file.exists()) { try { InputStream propertiesStream = file.openInputStream(); Properties properties = new Properties(); try { properties.load(propertiesStream); result = new PropertiesPropertySet(name, properties); } finally { closeSafely(propertiesStream); } } catch (IOException e) { CommonServices.getEntityAccess().getLogger().error(String.format("Could not read property file %s", file), e); } } return result; }
@Override public PropertySet getPropertySet(String name) { IFile file = _filesByTypeName.get().get(name); if (file == null) { throw new IllegalArgumentException(name + " is not the name of a properties file property set"); } PropertySet result = new EmptyPropertySet(name); if (file.exists()) { try { InputStream propertiesStream = file.openInputStream(); Properties properties = new Properties(); try { properties.load(propertiesStream); result = new PropertiesPropertySet(name, properties); } finally { closeSafely(propertiesStream); } } catch (IOException e) { CommonServices.getEntityAccess().getLogger().error(String.format("Could not read property file %s", file), e); } } return result; }
private static String readFile(IFile file) { Reader reader = null; try { reader = StreamUtil.getInputStreamReader(file.openInputStream()); return StreamUtil.getContent(reader); } catch (IOException e) { throw GosuExceptionUtil.forceThrow(e); } finally { try { StreamUtil.close(reader); } catch (IOException e) { // Ignore } } } }
public Object handleCall( Object ctx, Object... args ) { try { URL url = (URL) args[0]; // try { // return CommonServices.getFileSystem().getIFile(new File(url.toURI())); // } catch (URISyntaxException e) { // throw new RuntimeException(e); // } InputStream stream = CommonServices.getFileSystem().getIFile(url).openInputStream(); try { return XmlElementInternals.instance().parse( getType(), stream, url.toExternalForm(), true, null, args.length > 1 ? (XmlParseOptions) args[1] : null, url.toExternalForm() ); } finally { try { stream.close(); } catch ( Exception ex ) { // ignore } } } catch ( Exception ex ) { throw GosuExceptionUtil.forceThrow( ex ); } } };
private static XmlSchema loadSchemaWithCache(XmlSchemaIndex schemaIndex, URL targetUrl, String targetNamespace, XmlSchemaParseContext context, Map<Pair<URL, String>, XmlSchema> caches) throws IOException { Pair<URL, String> key = new Pair<URL, String>(targetUrl, targetNamespace == null ? XmlConstants.NULL_NS_URI : targetNamespace); XmlSchema schema = (caches == null) ? null : caches.get(key); if (schema == null) { // try { // return CommonServices.getFileSystem().getIFile(new File(url.toURI())); // } catch (URISyntaxException e) { // throw new RuntimeException(e); // } InputStream stream = CommonServices.getFileSystem().getIFile(targetUrl).openInputStream(); try { XmlElement schemaElement = XmlElementInternals.instance().parse( stream, targetUrl, null, null ); schema = parseSchema(schemaIndex, schemaElement, targetNamespace, targetUrl, context, false, caches ); } finally { if (stream != null) { stream.close(); } } if (caches != null) { caches.put(key, schema); } } else { schema = schema.copy(schemaIndex); } return schema; }
public static void getExtensions(Collection<String> result, IDirectory dir, String headerName) { IFile manifestFile = dir.file( "META-INF/MANIFEST.MF" ); if (manifestFile == null || !manifestFile.exists()) { return; } InputStream in = null; try { in = manifestFile.openInputStream(); Manifest manifest = new Manifest(in); scanManifest(result, manifest, headerName); } catch (Exception e) { // FIXME: For some reason, WebSphere changes JARs in WEB-INF/lib, breaking signatures. So ignore errors. ResourcePath path = dir.getPath(); String str = path != null ? path.getFileSystemPathString() : dir.toString(); CommonServices.getEntityAccess().getLogger().warn("Cannot read manifest from jar " + str + ", ignoring"); } finally { if (in != null) { try { in.close(); } catch (IOException e) { // Ignore } } } }
public AsmClass findClass( String fqn, IFile file ) { AsmClass asmClass = _cache.get( fqn ); if( asmClass == null ) { asmClass = _cache.get( fqn ); if( asmClass == null ) { try { asmClass = new AsmClass( _module, file.toURI() ); _cache.add( fqn, asmClass ); asmClass.init( getContent( file.openInputStream() ) ); } catch( IOException e ) { throw new RuntimeException( e ); } } } return asmClass; }