Java Code Examples for com.intellij.openapi.util.io.FileUtil#loadFileBytes()

The following examples show how to use com.intellij.openapi.util.io.FileUtil#loadFileBytes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SmallMapSerializer.java    From consulo with Apache License 2.0 5 votes vote down vote up
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);
  }
}
 
Example 2
Source File: VcsUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
public static byte[] getFileByteContent(@Nonnull File file) {
  try {
    return FileUtil.loadFileBytes(file);
  }
  catch (IOException e) {
    LOG.info(e);
    return null;
  }
}
 
Example 3
Source File: ShelvedBinaryContentRevision.java    From consulo with Apache License 2.0 5 votes vote down vote up
@javax.annotation.Nullable
@Override
public byte[] getBinaryContent() throws VcsException {
  try {
    return FileUtil.loadFileBytes(new File(myShelvedContentPath));
  }
  catch (IOException e) {
    throw new VcsException(e);
  }
}
 
Example 4
Source File: FormatterTestCase.java    From consulo with Apache License 2.0 4 votes vote down vote up
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);
      }
    }
  }
}
 
Example 5
Source File: CoreLocalVirtualFile.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public byte[] contentsToByteArray() throws IOException {
  return FileUtil.loadFileBytes(myIoFile);
}