@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()); }
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; }
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; }
public void close() throws IOException { super.close(); final BufferExposingByteArrayOutputStream byteStream = getByteStream(); myStorage.writeBytes( myRecordId, new ByteSequence(byteStream.getInternalBuffer(), 0, byteStream.size()), myFixedSize); }
/** * 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); }
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; }
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(); } }
public void close() throws IOException { super.close(); final BufferExposingByteArrayOutputStream _out = (BufferExposingByteArrayOutputStream) out; appendBytes(myRecordId, new ByteSequence(_out.getInternalBuffer(), 0, _out.size())); }
protected void doFlush() throws IOException { final BufferExposingByteArrayOutputStream _out = (BufferExposingByteArrayOutputStream) out; writeBytes(new ByteSequence(_out.getInternalBuffer(), 0, _out.size()), myFileId); }