本文整理汇总了Java中javax.tools.FileObject.openInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java FileObject.openInputStream方法的具体用法?Java FileObject.openInputStream怎么用?Java FileObject.openInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.tools.FileObject
的用法示例。
在下文中一共展示了FileObject.openInputStream方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findClass
import javax.tools.FileObject; //导入方法依赖的package包/类
@Override
protected Class<?> findClass(String name) throws ClassNotFoundException {
int n = name.lastIndexOf('.');
String pkg = n == -1 ? "" : name.substring(0, n);
String cls = name.substring(n + 1) + ".class";
byte[] b;
try {
FileObject obj = jfm.getFileForInput(jloc, pkg, cls);
try (InputStream is = obj.openInputStream()) {
b = is.readAllBytes();
}
} catch (IOException x) {
throw new ClassNotFoundException(x.getMessage(), x);
}
return defineClass(name, b, 0, b.length);
}
示例2: writeFileObjects
import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeFileObjects(JarOutputStream jos) throws IOException {
for (FileObject fo : fileObjects) {
String p = guessPath(fo);
JarEntry e = new JarEntry(p);
jos.putNextEntry(e);
try {
byte[] buf = new byte[1024];
try (BufferedInputStream in = new BufferedInputStream(fo.openInputStream())) {
int n;
while ((n = in.read(buf)) > 0)
jos.write(buf, 0, n);
} catch (IOException ex) {
error("Exception while adding " + fo.getName() + " to jar file", ex);
}
} finally {
jos.closeEntry();
}
}
}
示例3: generateInstanceResolver
import javax.tools.FileObject; //导入方法依赖的package包/类
private byte[] generateInstanceResolver(FileObject fo, Element e, File f,
Registration r) throws LayerGenerationException {
try {
InputStream is = fo.openInputStream();
org.openide.filesystems.FileObject tmp = FileUtil.createMemoryFileSystem().getRoot().createData("resolver.xml");
OutputStream os = tmp.getOutputStream();
for (;;) {
int ch = is.read();
if (ch == -1) {
break;
}
os.write(ch);
}
os.close();
is.close();
MIMEResolver resolver = MIMEResolverImpl.forDescriptor(tmp, false);
setFileChooserRelatedAttributes(r, resolver, f);
final byte[] almostResult = MIMEResolverImpl.toStream(resolver);
// XXX: it would be slightly shorter to return the array directly,
// but the XMLFileSystem insist on deserializing the value, it does
// not support returning plain byte[]
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(out);
oos.writeObject(almostResult);
oos.close();
return out.toByteArray();
} catch (IOException ex) {
final LayerGenerationException le = new LayerGenerationException("Cannot process " + fo, e);
le.initCause(ex);
throw le;
}
}
示例4: writeIfChanged
import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeIfChanged(byte[] b, FileObject file) throws IOException {
boolean mustWrite = false;
String event = "[No need to update file ";
if (force) {
mustWrite = true;
event = "[Forcefully writing file ";
} else {
InputStream in;
byte[] a;
try {
// regrettably, there's no API to get the length in bytes
// for a FileObject, so we can't short-circuit reading the
// file here
in = file.openInputStream();
a = readBytes(in);
if (!Arrays.equals(a, b)) {
mustWrite = true;
event = "[Overwriting file ";
}
} catch (FileNotFoundException e) {
mustWrite = true;
event = "[Creating file ";
}
}
if (util.verbose)
util.log(event + file + "]");
if (mustWrite) {
OutputStream out = file.openOutputStream();
out.write(b); /* No buffering, just one big write! */
out.close();
}
}
示例5: writeIfChanged
import javax.tools.FileObject; //导入方法依赖的package包/类
private void writeIfChanged(byte[] b, FileObject file) throws IOException {
boolean mustWrite = false;
String event = "[No need to update file ";
if (force) {
mustWrite = true;
event = "[Forcefully writing file ";
} else {
InputStream in;
byte[] a;
try {
// regrettably, there's no API to get the length in bytes
// for a FileObject, so we can't short-circuit reading the
// file here
in = file.openInputStream();
a = readBytes(in);
if (!Arrays.equals(a, b)) {
mustWrite = true;
event = "[Overwriting file ";
}
} catch (FileNotFoundException | NoSuchFileException e) {
mustWrite = true;
event = "[Creating file ";
}
}
if (util.verbose)
util.log(event + file + "]");
if (mustWrite) {
OutputStream out = file.openOutputStream();
out.write(b); /* No buffering, just one big write! */
out.close();
}
}