本文整理匯總了Java中com.intellij.openapi.util.io.FileUtil.loadFileBytes方法的典型用法代碼示例。如果您正苦於以下問題:Java FileUtil.loadFileBytes方法的具體用法?Java FileUtil.loadFileBytes怎麽用?Java FileUtil.loadFileBytes使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.intellij.openapi.util.io.FileUtil
的用法示例。
在下文中一共展示了FileUtil.loadFileBytes方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: copyWithFiltering
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void copyWithFiltering(File file, File outputFile) throws IOException {
final String encoding = myEncodingConfig != null? myEncodingConfig.getEncoding(file) : null;
PrintWriter writer;
try {
writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
}
catch (FileNotFoundException e) {
FileUtil.createIfDoesntExist(outputFile);
writer = encoding != null ? new PrintWriter(outputFile, encoding) : new PrintWriter(outputFile);
}
try {
final byte[] bytes = FileUtil.loadFileBytes(file);
final String text = encoding != null? new String(bytes, encoding) : new String(bytes);
doFilterText(text, getDelimitersPattern(), getProperties(), null, writer);
}
finally {
writer.close();
}
}
示例2: damageFile
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static void damageFile(MavenIndex index, String fileName, boolean fullDamage) throws IOException {
File cachesDir = index.getCurrentDataDir();
File file = new File(cachesDir, fileName);
assertTrue(file.exists());
if (fullDamage) {
FileWriter w = new FileWriter(file);
w.write("bad content");
w.close();
}
else {
byte[] content = FileUtil.loadFileBytes(file);
for (int i = 0; i < content.length; i+=2) {
content[i] = -1;
}
FileUtil.writeToFile(file, content);
}
}
示例3: isInstrumented
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static boolean isInstrumented(JpsModule m, final String classPath) {
File file = new File(JpsJavaExtensionService.getInstance().getOutputDirectory(m, false), classPath);
assertTrue(file.getAbsolutePath() + " not found", file.exists());
final Ref<Boolean> instrumented = Ref.create(false);
ClassVisitor visitor = new ClassVisitor(Opcodes.ASM5) {
@Override
public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) {
if (name.equals("$$$setupUI$$$")) {
instrumented.set(true);
}
return null;
}
};
try {
ClassReader reader = new ClassReader(FileUtil.loadFileBytes(file));
reader.accept(visitor, 0);
return instrumented.get();
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
示例4: restoreFileFromCachedContent
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public static boolean restoreFileFromCachedContent(final VirtualFile parent,
final String name,
final String revision,
boolean makeReadOnly) {
try {
final File cachedContentFile = getCachedContentFile(parent, name, revision);
if (cachedContentFile == null) return false;
final byte[] content = FileUtil.loadFileBytes(cachedContentFile);
final File file = new File(parent.getPath(), name);
FileUtil.createIfDoesntExist(file);
if (!file.canWrite() && !file.setWritable(true)) return false;
FileUtil.writeToFile(file, content);
if (makeReadOnly && !file.setWritable(false)) return false;
return file.setLastModified(cachedContentFile.lastModified());
}
catch (IOException e) {
LOG.error(e);
return false;
}
}
示例5: processClass
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public void processClass(String qualifiedName, File file) throws Throwable {
final List<ReferenceType> vmClasses = myVirtualMachineProxy.classesByName(qualifiedName);
if (vmClasses.isEmpty()) {
return;
}
final byte[] content = FileUtil.loadFileBytes(file);
if (vmClasses.size() == 1) {
myRedefineMap.put(vmClasses.get(0), content);
if (myRedefineMap.size() >= CLASSES_CHUNK_SIZE) {
processChunk();
}
return;
}
int redefinedVersionsCount = 0;
Throwable error = null;
for (ReferenceType vmClass : vmClasses) {
try {
myVirtualMachineProxy.redefineClasses(Collections.singletonMap(vmClass, content));
redefinedVersionsCount++;
}
catch (Throwable t) {
error = t;
}
}
if (redefinedVersionsCount == 0) {
throw error;
}
if (redefinedVersionsCount < vmClasses.size()) {
myPartiallyRedefinedClassesCount++;
}
myProcessedClassesCount++;
}
示例6: getBytes
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static byte[] getBytes(File file) {
try {
return FileUtil.loadFileBytes(file);
}
catch (IOException e) {
return Attachment.getBytes(MessageFormat.format(ERROR_MESSAGE_PATTERN, e.getMessage()));
}
}
示例7: init
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void init() {
try {
final byte[] bytes = FileUtil.loadFileBytes(myFile);
final DataInputStream dis = new DataInputStream(new UnsyncByteArrayInputStream(bytes));
final int size = dis.readInt();
for (int i = 0; i < size; i++) {
final KeyWrapper<K> keyWrapper = new KeyWrapper<K>(myKeyDescriptor, myKeyDescriptor.read(dis));
final V value = myValueExternalizer.read(dis);
myMap.put(keyWrapper, value);
}
} catch (FileNotFoundException ignore) {
} catch (IOException e) {
LOG.error(e);
}
}
示例8: getFileByteContent
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
public static byte[] getFileByteContent(@NotNull File file) {
try {
return FileUtil.loadFileBytes(file);
}
catch (IOException e) {
LOG.info(e);
return null;
}
}
示例9: getBinaryContent
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
@Override
public byte[] getBinaryContent() throws VcsException {
try {
return FileUtil.loadFileBytes(new File(myShelvedContentPath));
}
catch (IOException e) {
throw new VcsException(e);
}
}
示例10: getRepositoryFromSettings
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
public static String getRepositoryFromSettings(final File file) {
try {
byte[] bytes = FileUtil.loadFileBytes(file);
return expandProperties(MavenJDOMUtil.findChildValueByPath(MavenJDOMUtil.read(bytes, null), "localRepository", null));
}
catch (IOException e) {
return null;
}
}
示例11: getStoredContentForFile
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
public static byte[] getStoredContentForFile(VirtualFile file, final String originalRevision) {
File ioFile = CvsVfsUtil.getFileFor(file);
try {
File storedRevisionFile = new File(ioFile.getParentFile(), ".#" + ioFile.getName() + "." + originalRevision);
if (!storedRevisionFile.isFile()) return null;
return FileUtil.loadFileBytes(storedRevisionFile);
}
catch (IOException e) {
LOG.error(e);
return null;
}
}
示例12: getCachedStoredContent
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
@Nullable
public static byte[] getCachedStoredContent(final VirtualFile parent, final String name, final String revision) {
try {
File storedRevisionFile = getCachedContentFile(parent, name, revision);
if (storedRevisionFile == null) return null;
return FileUtil.loadFileBytes(storedRevisionFile);
}
catch (IOException e) {
LOG.error(e);
return null;
}
}
示例13: readFile
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private static byte[] readFile(File workingFile) throws VcsException {
try {
return FileUtil.loadFileBytes(workingFile);
}
catch (IOException e) {
throw new VcsException(e);
}
}
示例14: prepareTest
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private Class prepareTest(boolean withDebugInfo) throws IOException {
String base = JavaTestUtil.getJavaTestDataPath() + "/compiler/notNullVerification/";
final String baseClassName = getTestName(false);
String path = base + baseClassName;
String javaPath = path + ".java";
File classesDir = FileUtil.createTempDirectory(baseClassName, "output");
try {
List<String> cmdLine = ContainerUtil.newArrayList("-classpath", base + "annotations.jar", "-d", classesDir.getAbsolutePath());
if (withDebugInfo) {
cmdLine.add("-g");
}
cmdLine.add(javaPath);
com.sun.tools.javac.Main.compile(ArrayUtil.toStringArray(cmdLine));
Class mainClass = null;
final File[] files = classesDir.listFiles();
assertNotNull(files);
boolean modified = false;
MyClassLoader classLoader = new MyClassLoader(getClass().getClassLoader());
for (File file : files) {
final String fileName = file.getName();
byte[] content = FileUtil.loadFileBytes(file);
ClassReader reader = new ClassReader(content, 0, content.length);
ClassWriter writer = new PsiClassWriter(myFixture.getProject(), myJava6);
modified |= NotNullVerifyingInstrumenter.processClassFile(reader, writer);
byte[] instrumented = writer.toByteArray();
final String className = FileUtil.getNameWithoutExtension(fileName);
final Class aClass = classLoader.doDefineClass(className, instrumented);
if (className.equals(baseClassName)) {
mainClass = aClass;
}
}
assertTrue(modified);
assertNotNull("Class " + baseClassName + " not found!", mainClass);
return mainClass;
}
finally {
FileUtil.delete(classesDir);
}
}
示例15: doSanityTestForFile
import com.intellij.openapi.util.io.FileUtil; //導入方法依賴的package包/類
private void doSanityTestForFile(final File subFile, final List<File> failedFiles, final boolean formatWithPsi)
throws IOException, IncorrectOperationException {
if (subFile.isFile() && subFile.getName().endsWith(getFileExtension())) {
final byte[] bytes = FileUtil.loadFileBytes(subFile);
final String text = new String(bytes);
final String fileName = "before." + getFileExtension();
final PsiFile file = PsiFileFactory.getInstance(getProject()).createFileFromText(fileName, getFileType(fileName), StringUtil.convertLineSeparators(text), LocalTimeCounter.currentTime(), true);
try {
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().runWriteAction(new Runnable() {
@Override
public void run() {
try {
if (formatWithPsi) {
performFormatting(file);
}
else {
performFormattingWithDocument(file);
}
}
catch (Throwable e) {
//noinspection CallToPrintStackTrace
e.printStackTrace();
failedFiles.add(subFile);
}
//noinspection UseOfSystemOutOrSystemErr
System.out.println(subFile.getPath() + ": finished");
}
});
}
}, "", null);
}
finally {
final VirtualFile virtualFile = file.getVirtualFile();
if (virtualFile != null) {
((UndoManagerImpl)UndoManager.getInstance(getProject())).clearUndoRedoQueueInTests(virtualFile);
((UndoManagerImpl)UndoManager.getGlobalInstance()).clearUndoRedoQueueInTests(virtualFile);
}
}
}
}