コード例 #1
0
 @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());
 }
コード例 #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;
  }
コード例 #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;
  }
コード例 #4
0
ファイル: AbstractStorage.java プロジェクト: ernestp/consulo
 public void close() throws IOException {
   super.close();
   final BufferExposingByteArrayOutputStream byteStream = getByteStream();
   myStorage.writeBytes(
       myRecordId,
       new ByteSequence(byteStream.getInternalBuffer(), 0, byteStream.size()),
       myFixedSize);
 }
コード例 #5
0
ファイル: StorageUtil.java プロジェクト: ngoanhtan/consulo
 /**
  * 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);
 }
コード例 #6
0
ファイル: StorageUtil.java プロジェクト: ngoanhtan/consulo
  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;
  }
コード例 #7
0
  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();
    }
  }
コード例 #8
0
ファイル: AbstractStorage.java プロジェクト: ernestp/consulo
 public void close() throws IOException {
   super.close();
   final BufferExposingByteArrayOutputStream _out = (BufferExposingByteArrayOutputStream) out;
   appendBytes(myRecordId, new ByteSequence(_out.getInternalBuffer(), 0, _out.size()));
 }
コード例 #9
0
 protected void doFlush() throws IOException {
   final BufferExposingByteArrayOutputStream _out = (BufferExposingByteArrayOutputStream) out;
   writeBytes(new ByteSequence(_out.getInternalBuffer(), 0, _out.size()), myFileId);
 }