@Override
 public void save(@NotNull DataOutput out, PsiJavaFileStub value) throws IOException {
   BufferExposingByteArrayOutputStream buffer = new BufferExposingByteArrayOutputStream();
   mySerializer.serialize(value, buffer);
   out.writeInt(buffer.size());
   out.write(buffer.getInternalBuffer(), 0, buffer.size());
 }
Exemplo n.º 2
0
  public static Image loadFromStream(@NotNull final InputStream inputStream, final int scale) {
    if (scale <= 0) throw new IllegalArgumentException("Scale must 1 or more");
    try {
      BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
      try {
        byte[] buffer = new byte[1024];
        while (true) {
          final int n = inputStream.read(buffer);
          if (n < 0) break;
          outputStream.write(buffer, 0, n);
        }
      } finally {
        inputStream.close();
      }

      Image image =
          Toolkit.getDefaultToolkit()
              .createImage(outputStream.getInternalBuffer(), 0, outputStream.size());

      waitForImage(image);

      if (UIUtil.isRetina() && scale > 1) {
        image = RetinaImage.createFrom(image, scale, ourComponent);
      }

      return image;
    } catch (Exception ex) {
      LOG.error(ex);
    }

    return null;
  }
Exemplo n.º 3
0
  private static Image load(@NotNull final InputStream inputStream, final int scale) {
    if (scale <= 0) throw new IllegalArgumentException("Scale must be 1 or greater");
    try {
      BufferExposingByteArrayOutputStream outputStream = new BufferExposingByteArrayOutputStream();
      try {
        byte[] buffer = new byte[1024];
        while (true) {
          final int n = inputStream.read(buffer);
          if (n < 0) break;
          outputStream.write(buffer, 0, n);
        }
      } finally {
        inputStream.close();
      }

      Image image =
          Toolkit.getDefaultToolkit()
              .createImage(outputStream.getInternalBuffer(), 0, outputStream.size());

      waitForImage(image);

      return image;
    } catch (Exception ex) {
      LOG.error(ex);
    }

    return null;
  }
Exemplo n.º 4
0
 public void close() throws IOException {
   super.close();
   final BufferExposingByteArrayOutputStream byteStream = getByteStream();
   myStorage.writeBytes(
       myRecordId,
       new ByteSequence(byteStream.getInternalBuffer(), 0, byteStream.size()),
       myFixedSize);
 }
Exemplo n.º 5
0
 /**
  * You must call {@link StreamProvider#isApplicable(String,
  * com.intellij.openapi.components.RoamingType)} before
  */
 public static void doSendContent(
     @NotNull StreamProvider provider,
     @NotNull String fileSpec,
     @NotNull Parent element,
     @NotNull RoamingType type,
     boolean async)
     throws IOException {
   // we should use standard line-separator (\n) - stream provider can share file content on any OS
   BufferExposingByteArrayOutputStream content = elementToBytes(element, false);
   provider.saveContent(fileSpec, content.getInternalBuffer(), content.size(), type, async);
 }
Exemplo n.º 6
0
  public static boolean equal(byte[] a1, @NotNull BufferExposingByteArrayOutputStream out) {
    int length = out.size();
    if (a1.length != length) {
      return false;
    }

    byte[] internalBuffer = out.getInternalBuffer();
    for (int i = 0; i < length; i++) {
      if (a1[i] != internalBuffer[i]) {
        return false;
      }
    }
    return true;
  }
Exemplo n.º 7
0
 @NotNull
 public static VirtualFile writeFile(
     @Nullable File file,
     @NotNull Object requestor,
     @Nullable VirtualFile virtualFile,
     @NotNull BufferExposingByteArrayOutputStream content,
     @Nullable LineSeparator lineSeparatorIfPrependXmlProlog)
     throws IOException {
   AccessToken token = ApplicationManager.getApplication().acquireWriteActionLock(null);
   try {
     if (file != null && (virtualFile == null || !virtualFile.isValid())) {
       virtualFile = getOrCreateVirtualFile(requestor, file);
     }
     assert virtualFile != null;
     OutputStream out = virtualFile.getOutputStream(requestor);
     try {
       if (lineSeparatorIfPrependXmlProlog != null) {
         out.write(XML_PROLOG);
         out.write(lineSeparatorIfPrependXmlProlog.getSeparatorBytes());
       }
       content.writeTo(out);
     } finally {
       out.close();
     }
     return virtualFile;
   } catch (FileNotFoundException e) {
     if (virtualFile == null) {
       throw e;
     } else {
       throw new ReadOnlyModificationException(virtualFile);
     }
   } finally {
     token.finish();
   }
 }
  private static void saveOnDisk(BufferExposingByteArrayOutputStream bytes, final File file)
      throws IOException {
    FileOutputStream fos = null;
    try {
      fos = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
      FileUtil.createIfDoesntExist(file);
    }

    if (fos == null) {
      fos = new FileOutputStream(file);
    }
    try {
      fos.write(bytes.getInternalBuffer(), 0, bytes.size());
    } finally {
      fos.close();
    }
  }
 @NotNull
 public byte[] getOutput() {
   return myOutput.toByteArray();
 }
Exemplo n.º 10
0
 public void close() throws IOException {
   super.close();
   final BufferExposingByteArrayOutputStream _out = (BufferExposingByteArrayOutputStream) out;
   appendBytes(myRecordId, new ByteSequence(_out.getInternalBuffer(), 0, _out.size()));
 }
Exemplo n.º 11
0
 protected void doFlush() throws IOException {
   final BufferExposingByteArrayOutputStream _out = (BufferExposingByteArrayOutputStream) out;
   writeBytes(new ByteSequence(_out.getInternalBuffer(), 0, _out.size()), myFileId);
 }