本文整理汇总了Java中org.openide.filesystems.FileObject.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.getInputStream方法的具体用法?Java FileObject.getInputStream怎么用?Java FileObject.getInputStream使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.openide.filesystems.FileObject
的用法示例。
在下文中一共展示了FileObject.getInputStream方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadSnapshotFromFileObject
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private LoadedSnapshot loadSnapshotFromFileObject(FileObject selectedFile)
throws IOException {
DataInputStream dis = null;
try {
InputStream is = selectedFile.getInputStream();
BufferedInputStream bis = new BufferedInputStream(is);
dis = new DataInputStream(bis);
LoadedSnapshot ls = LoadedSnapshot.loadSnapshot(dis);
if (ls != null) {
ls.setFile(FileUtil.toFile(selectedFile));
ls.setProject(findProjectForSnapshot(selectedFile));
}
return ls;
} finally {
if (dis != null) {
dis.close();
}
}
}
示例2: readJUnitFileHeader
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private boolean readJUnitFileHeader(FileObject fo) throws IOException {
InputStream is = fo.getInputStream();
try {
BufferedReader input = new BufferedReader(new InputStreamReader(is, getEncoding()));
String line;
int maxLines = 100;
while (null != (line = input.readLine()) && maxLines > 0) {
maxLines--;
if (line.contains("junit.framework.Test") || // NOI18N
line.contains("org.junit.Test") || // NOI18N
line.contains("junit.framework.*") || // NOI18N
line.contains("org.junit.*")) { // NOI18N
return true;
}
}
} finally {
is.close();
}
return false;
}
示例3: getReader
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private Reader getReader(FileObject fo, String encoding, FileObject type, String secondFileExt) throws FileNotFoundException {
if (encoding != null) {
try {
return new InputStreamReader(fo.getInputStream(), encoding);
} catch (UnsupportedEncodingException ueex) {
ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ueex);
}
}
Reader r = null;
String ext = type.getExt();
if (!"java".equalsIgnoreCase(ext) || !ext.equals(secondFileExt)) {// We read the encoding for Java files explicitely
// If it's not defined, read with default encoding from stream (because of guarded blocks)
// But when the extensions of the two files are different (comparing Java files with something else),
// we have to use the Document approach for both due to possible different line-endings.
r = getReaderFromEditorSupport(fo, type);
if (r == null) {
r = getReaderFromKit(null, fo, type.getMIMEType());
}
}
if (r == null) {
// Fallback, use current encoding
r = new InputStreamReader(fo.getInputStream());
}
return r;
}
示例4: isBuildScriptUpToDate
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static boolean isBuildScriptUpToDate(@NonNull final Project project) {
final FileObject prjDir = project.getProjectDirectory();
if (prjDir == null) {
return false;
}
final FileObject remoteBuildScript = prjDir.getFileObject(BUILD_SCRIPT_PATH);
if (remoteBuildScript == null) {
return false;
}
try {
final long scriptCRC;
try (final InputStream in = new BufferedInputStream(remoteBuildScript.getInputStream())) {
scriptCRC = calculateCRC(in);
}
Long templateCRC = templateCRCCache;
if (templateCRC == null) {
try (final InputStream in = new BufferedInputStream(
RemotePlatformProjectSaver.class.getResourceAsStream(BUILD_SCRIPT_PROTOTYPE))) {
templateCRCCache = templateCRC = calculateCRC(in);
}
}
return scriptCRC == templateCRC;
} catch (IOException ioe) {
return false;
}
}
示例5: loadPublicPackagesPatterns
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static List<Pattern> loadPublicPackagesPatterns(Project project) {
List<Pattern> toRet = new ArrayList<Pattern>();
String[] params = PluginPropertyUtils.getPluginPropertyList(project,
MavenNbModuleImpl.GROUPID_MOJO, MavenNbModuleImpl.NBM_PLUGIN, //NOI18N
"publicPackages", "publicPackage", "manifest"); //NOI18N
if (params != null) {
toRet = prepareMavenPublicPackagesPatterns(params);
} else {
FileObject obj = project.getProjectDirectory().getFileObject(MANIFEST_PATH);
if (obj != null) {
InputStream in = null;
try {
in = obj.getInputStream();
Manifest man = new Manifest();
man.read(in);
String value = man.getMainAttributes().getValue(ATTR_PUBLIC_PACKAGE);
toRet = prepareManifestPublicPackagesPatterns(value);
} catch (Exception ex) {
Exceptions.printStackTrace(ex);
} finally {
IOUtil.close(in);
}
}
}
return toRet;
}
示例6: getResourceContent
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**Allows access to non-Java resources. The content of this InputStream will
* include all changes done through {@link #getResourceOutput(org.openide.filesystems.FileObject) }
* before calling this method.
*
* @param file whose content should be returned
* @return the file's content
* @throws IOException if something goes wrong while opening the file
* @throws IllegalArgumentException if {@code file} parameter is null, or
* if it represents a Java file
*/
public @NonNull InputStream getResourceContent(@NonNull FileObject file) throws IOException, IllegalArgumentException {
Parameters.notNull("file", file);
if ("text/x-java".equals(file.getMIMEType("text/x-java")))
throw new IllegalArgumentException("Cannot access Java files");
byte[] newContent = resourceContentChanges != null ? resourceContentChanges.get(file) : null;
if (newContent == null) {
final Document doc = BatchUtilities.getDocument(file);
if (doc != null) {
final String[] result = new String[1];
doc.render(new Runnable() {
@Override public void run() {
try {
result[0] = doc.getText(0, doc.getLength());
} catch (BadLocationException ex) {
Exceptions.printStackTrace(ex);
}
}
});
if (result[0] != null) {
ByteBuffer encoded = FileEncodingQuery.getEncoding(file).encode(result[0]);
byte[] encodedBytes = new byte[encoded.remaining()];
encoded.get(encodedBytes);
return new ByteArrayInputStream(encodedBytes);
}
}
return file.getInputStream();
} else {
return new ByteArrayInputStream(newContent);
}
}
示例7: getInstance
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public synchronized PaletteItemNode getInstance() {
PaletteItemNode node = refNode.get();
if (node != null)
return node;
FileObject file = xmlDataObject.getPrimaryFile();
if (file.getSize() == 0L) // item file is empty
return null;
PaletteItemHandler handler = new PaletteItemHandler();
try {
XMLReader reader = getXMLReader();
FileObject fo = xmlDataObject.getPrimaryFile();
String urlString = fo.getURL().toExternalForm();
InputSource is = new InputSource(fo.getInputStream());
is.setSystemId(urlString);
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.parse(is);
}
catch (SAXException saxe) {
Logger.getLogger( getClass().getName() ).log( Level.INFO, null, saxe );
return null;
}
catch (IOException ioe) {
Logger.getLogger( getClass().getName() ).log( Level.INFO, null, ioe );
return null;
}
if( handler.isError() )
return null;
node = createPaletteItemNode(handler);
refNode = new WeakReference<PaletteItemNode>(node);
return node;
}
示例8: read
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Reads the content of the file.
*
* @param file file whose content should be read.
* @return the content of the file.
* @throws IOException when the reading fails.
*/
private static String read(FileObject file, String encoding) throws IOException {
InputStream is = file.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is, encoding));
StringBuilder sb = new StringBuilder();
try {
String s;
while ((s=br.readLine()) != null) {
sb.append(s).append('\n');
}
} finally {
br.close();
}
return sb.toString();
}
示例9: ref
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
public void ref(FileObject fo) {
if (fo.isValid()) {
try {
BufferedReader br = new BufferedReader(new InputStreamReader(fo.getInputStream()));
getRef().println("==>" + fo.getName());
String s = br.readLine();
while (s != null) {
getRef().println(s);
s = br.readLine();
}
} catch (IOException ioe) {
fail(ioe);
}
}
}
示例10: findProfileInManifest
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@NonNull
private Union2<Profile,String> findProfileInManifest(@NonNull URL root) {
final ArchiveCache ac = context.getArchiveCache();
Union2<Profile,String> res;
final ArchiveCache.Key key = ac.createKey(root);
if (key != null) {
res = ac.getProfile(key);
if (res != null) {
return res;
}
}
String profileName = null;
final FileObject rootFo = URLMapper.findFileObject(root);
if (rootFo != null) {
final FileObject manifestFile = rootFo.getFileObject(RES_MANIFEST);
if (manifestFile != null) {
try {
try (InputStream in = manifestFile.getInputStream()) {
final Manifest manifest = new Manifest(in);
final Attributes attrs = manifest.getMainAttributes();
profileName = attrs.getValue(ATTR_PROFILE);
}
} catch (IOException ioe) {
LOG.log(
Level.INFO,
"Cannot read Profile attribute from: {0}", //NOI18N
FileUtil.getFileDisplayName(manifestFile));
}
}
}
final Profile profile = Profile.forName(profileName);
res = profile != null ?
Union2.<Profile,String>createFirst(profile) :
Union2.<Profile,String>createSecond(profileName);
if (key != null) {
ac.putProfile(key, res);
}
return res;
}
示例11: testCreateLayerEntryWithoutLocalizingBundle
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/** @see "#64273" */
public void testCreateLayerEntryWithoutLocalizingBundle() throws Exception {
NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module");
project.getProjectDirectory().getFileObject("src/org/example/module/resources/Bundle.properties").delete();
FileObject mf = project.getProjectDirectory().getFileObject("manifest.mf");
EditableManifest m;
InputStream is = mf.getInputStream();
try {
m = new EditableManifest(is);
} finally {
is.close();
}
m.removeAttribute("OpenIDE-Module-Localizing-Bundle", null);
OutputStream os = mf.getOutputStream();
try {
m.write(os);
} finally {
os.close();
}
CreatedModifiedFiles cmf = new CreatedModifiedFiles(project);
Operation op = cmf.createLayerEntry("f", null, null, "F!", null);
cmf.add(op);
cmf.run();
String[] supposedContent = new String[] {
"<filesystem>",
"<file name=\"f\"/>",
"</filesystem>"
};
assertLayerContent(supposedContent,
new File(getWorkDir(), "module/src/org/example/module/resources/layer.xml"));
}
示例12: getURLString
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
/**
* Gets a <code>URL</code> string from the underlying .url file.
* The user is notified if an error occures during reading the file.
* If there are multiple lines of text in the file, only the first one is
* returned and no error is reported.
*
* @return <code>URL</code> string stored in the file,
* an empty string if the file is empty,
* or <code>null</code> if an error occured while reading the file
*/
String getURLString() {
FileObject urlFile = getPrimaryFile();
if (!urlFile.isValid()) {
return null;
}
String urlString = null;
InputStream is = null;
try {
is = urlFile.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
urlString = findUrlInFileContent(br);
} catch (FileNotFoundException fne) {
ErrorManager.getDefault().notify(ErrorManager.WARNING, fne);
return null;
} catch (IOException ioe) {
ErrorManager.getDefault().notify(ErrorManager.WARNING, ioe);
return null;
} finally {
if (is != null) {
try {
is.close ();
} catch (IOException e) {
ErrorManager.getDefault().notify(
ErrorManager.INFORMATIONAL, e);
}
}
}
if (urlString == null) {
/*
* If the file is empty, return an empty string.
* <null> is reserved for notifications of failures.
*/
urlString = ""; //NOI18N
}
return urlString;
}
示例13: readModuleName
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
@CheckForNull
private static String readModuleName(@NonNull FileObject moduleInfo) throws IOException {
try (final InputStream in = new BufferedInputStream(moduleInfo.getInputStream())) {
final ClassFile clz = new ClassFile(in, false);
final Module modle = clz.getModule();
return modle != null ?
modle.getName() :
null;
}
}
示例14: copyByteAfterByte
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
private static void copyByteAfterByte(FileObject content, FileObject target) throws IOException {
OutputStream os = target.getOutputStream();
try {
InputStream is = content.getInputStream();
try {
FileUtil.copy(is, os);
} finally {
is.close();
}
} finally {
os.close();
}
}
示例15: readFromFile
import org.openide.filesystems.FileObject; //导入方法依赖的package包/类
static String readFromFile(FileObject fo) throws Exception {
InputStream in = fo.getInputStream();
int s = (int)fo.getSize();
byte[] arr = new byte[s];
assertEquals("All read", s, in.read(arr));
return new String(arr);
}