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

The following examples show how to use com.intellij.openapi.util.io.FileUtil#loadBytes() . 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: LoadAllVfsStoredContentsAction.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean processFile(NewVirtualFile file) {
  if (file.isDirectory() || file.is(VFileProperty.SPECIAL)) {
    return true;
  }
  try {
    try (InputStream stream = PersistentFS.getInstance().getInputStream(file)) {
      // check if it's really cached in VFS
      if (!(stream instanceof DataInputStream)) return true;
      byte[] bytes = FileUtil.loadBytes(stream);
      totalSize.addAndGet(bytes.length);
      count.incrementAndGet();
      ProgressManager.getInstance().getProgressIndicator().setText(file.getPresentableUrl());
    }
  }
  catch (IOException e) {
    LOG.error(e);
  }
  return true;
}
 
Example 2
Source File: GeneralCommandLineTest.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static String execAndGetOutput(GeneralCommandLine commandLine, @Nullable String encoding) throws Exception {
  Process process = commandLine.createProcess();
  byte[] bytes = FileUtil.loadBytes(process.getInputStream());
  String output = encoding != null ? new String(bytes, encoding) : new String(bytes);
  int result = process.waitFor();
  assertEquals("Command:\n" + commandLine.getCommandLineString() + "\nOutput:\n" + output, 0, result);
  return output;
}
 
Example 3
Source File: FileAttribute.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public byte[] readAttributeBytes(VirtualFile file) throws IOException {
  final DataInputStream stream = readAttribute(file);
  if (stream == null) return null;

  try {
    int len = stream.readInt();
    return FileUtil.loadBytes(stream, len);
  }
  finally {
    stream.close();
  }
}
 
Example 4
Source File: JBZipEntry.java    From consulo with Apache License 2.0 5 votes vote down vote up
public byte[] getData() throws IOException {
  if (size == -1) throw new IOException("no data");

  final InputStream stream = getInputStream();
  try {
    return FileUtil.loadBytes(stream, (int)size);
  }
  finally {
    stream.close();
  }
}
 
Example 5
Source File: ZipHandler.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public byte[] contentsToByteArray(@Nonnull String relativePath) throws IOException {
  FileAccessorCache.Handle<ArchiveFile> zipRef;

  try {
    zipRef = getZipFileHandle();
  }
  catch (RuntimeException ex) {
    Throwable cause = ex.getCause();
    if (cause instanceof IOException) throw (IOException)cause;
    throw ex;
  }

  try {
    ArchiveFile zip = zipRef.get();
    ArchiveEntry entry = zip.getEntry(relativePath);
    if (entry != null) {
      InputStream stream = zip.getInputStream(entry);
      if (stream != null) {
        // ZipFile.c#Java_java_util_zip_ZipFile_read reads data in 8K (stack allocated) blocks - no sense to create BufferedInputStream
        try {
          return FileUtil.loadBytes(stream, (int)entry.getSize());
        }
        finally {
          stream.close();
        }
      }
    }
  }
  finally {
    zipRef.release();
  }

  throw new FileNotFoundException(getFile() + "!/" + relativePath);
}
 
Example 6
Source File: UrlUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static String loadText(URL url) throws IOException {
  try (InputStream stream = new BufferedInputStream(URLUtil.openStream(url))) {
    return new String(FileUtil.loadBytes(stream), FileTemplate.ourEncoding);
  }
}
 
Example 7
Source File: CommonsImagingImageReaderSpi.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public byte[] getAll() throws IOException {
  return FileUtil.loadBytes(getInputStream());
}