@Override public long length() { if (onDiskFile == null) { return super.length(); } return onDiskFile.length(); }
/** * Create a new wrapper around a temporary buffer. * * @param buffer * the buffer to initialize stream and length from. The * buffer will be destroyed on {@link #close()} * @throws IOException * in case of an error opening the stream to the buffer. */ public LfsInputStream(TemporaryBuffer buffer) throws IOException { this.stream = buffer.openInputStreamWithAutoDestroy(); this.length = buffer.length(); }
/** * Convert this buffer's contents into a contiguous byte array. * <p> * The buffer is only complete after {@link #close()} has been invoked. * * @return the complete byte array; length matches {@link #length()}. * @throws java.io.IOException * an error occurred reading from a local temporary file */ public byte[] toByteArray() throws IOException { final long len = length(); if (Integer.MAX_VALUE < len) throw new OutOfMemoryError(JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; for (Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } return out; }
/** * Convert this buffer's contents into a contiguous byte array. If this size * of the buffer exceeds the limit only return the first {@code limit} bytes * <p> * The buffer is only complete after {@link #close()} has been invoked. * * @param limit * the maximum number of bytes to be returned * @return the byte array limited to {@code limit} bytes. * @throws java.io.IOException * an error occurred reading from a local temporary file * @since 4.2 */ public byte[] toByteArray(int limit) throws IOException { final long len = Math.min(length(), limit); if (Integer.MAX_VALUE < len) throw new OutOfMemoryError( JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; for (Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } return out; }
final long len = buf.length(); for (int curAttempt = 0; curAttempt < maxAttempts; curAttempt++) { final HttpURLConnection c = open("PUT", bucket, key); //$NON-NLS-1$
private ObjectId insertMergeResult(TemporaryBuffer buf, Attributes attributes) throws IOException { InputStream in = buf.openInputStream(); try (LfsInputStream is = LfsFactory.getInstance().applyCleanFilter( getRepository(), in, buf.length(), attributes.get(Constants.ATTR_MERGE))) { return getObjectInserter().insert(OBJ_BLOB, is.getLength(), is); } }
@Override public long length() { if (onDiskFile == null) { return super.length(); } return onDiskFile.length(); }
/** {@inheritDoc} */ @Override public long getContentLength() { if (contentLength != null) return contentLength.intValue(); return buffer.length(); }
public long getContentLength() { if (contentLength != null) return contentLength.intValue(); return buffer.length(); }
public long length() { if (onDiskFile == null) { return super.length(); } return onDiskFile.length(); }
public long getContentLength() { if (contentLength != null) return contentLength.intValue(); return buffer.length(); }
try (GZIPOutputStream gzip = new GZIPOutputStream(buf)) { out.writeTo(gzip, null); if (out.length() < buf.length()) buf = out; } catch (IOException err) { ENCODING_GZIP); conn.setFixedLengthStreamingMode((int) buf.length()); try (OutputStream httpOut = conn.getOutputStream()) { buf.writeTo(httpOut, null);
NB.encodeInt32(tmp, 4, (int) bb.length()); dos.write(tmp, 0, 8); bb.writeTo(dos, null);
/** * Create a new wrapper around a temporary buffer. * * @param buffer * the buffer to initialize stream and length from. The * buffer will be destroyed on {@link #close()} * @throws IOException * in case of an error opening the stream to the buffer. */ public LfsInputStream(TemporaryBuffer buffer) throws IOException { this.stream = buffer.openInputStreamWithAutoDestroy(); this.length = buffer.length(); }
/** * Convert this buffer's contents into a contiguous byte array. * <p> * The buffer is only complete after {@link #close()} has been invoked. * * @return the complete byte array; length matches {@link #length()}. * @throws java.io.IOException * an error occurred reading from a local temporary file */ public byte[] toByteArray() throws IOException { final long len = length(); if (Integer.MAX_VALUE < len) throw new OutOfMemoryError(JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; for (Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } return out; }
/** * Convert this buffer's contents into a contiguous byte array. * <p> * The buffer is only complete after {@link #close()} has been invoked. * * @return the complete byte array; length matches {@link #length()}. * @throws IOException * an error occurred reading from a local temporary file * @throws OutOfMemoryError * the buffer cannot fit in memory */ public byte[] toByteArray() throws IOException { final long len = length(); if (Integer.MAX_VALUE < len) throw new OutOfMemoryError(JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; for (final Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } return out; }
/** * Convert this buffer's contents into a contiguous byte array. If this size * of the buffer exceeds the limit only return the first {@code limit} bytes * <p> * The buffer is only complete after {@link #close()} has been invoked. * * @param limit * the maximum number of bytes to be returned * @return the byte array limited to {@code limit} bytes. * @throws java.io.IOException * an error occurred reading from a local temporary file * @since 4.2 */ public byte[] toByteArray(int limit) throws IOException { final long len = Math.min(length(), limit); if (Integer.MAX_VALUE < len) throw new OutOfMemoryError( JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; for (Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } return out; }
/** * Convert this buffer's contents into a contiguous byte array. If this size * of the buffer exceeds the limit only return the first {@code limit} bytes * <p> * The buffer is only complete after {@link #close()} has been invoked. * * @param limit * the maximum number of bytes to be returned * * @return the byte array limited to {@code limit} bytes. * @throws IOException * an error occurred reading from a local temporary file * @throws OutOfMemoryError * the buffer cannot fit in memory * * @since 4.2 */ public byte[] toByteArray(int limit) throws IOException { final long len = Math.min(length(), limit); if (Integer.MAX_VALUE < len) throw new OutOfMemoryError( JGitText.get().lengthExceedsMaximumArraySize); final byte[] out = new byte[(int) len]; int outPtr = 0; for (final Block b : blocks) { System.arraycopy(b.buffer, 0, out, outPtr, b.count); outPtr += b.count; } return out; }
void sendRequest() throws IOException { // Try to compress the content, but only if that is smaller. TemporaryBuffer buf = new TemporaryBuffer.Heap(http.postBuffer); try { GZIPOutputStream gzip = new GZIPOutputStream(buf); out.writeTo(gzip, null); gzip.close(); if (out.length() < buf.length()) buf = out; } catch (IOException err) { // Most likely caused by overflowing the buffer, meaning // its larger if it were compressed. Don't compress. buf = out; } openStream(); if (buf != out) conn.setRequestProperty(HDR_CONTENT_ENCODING, ENCODING_GZIP); conn.setFixedLengthStreamingMode((int) buf.length()); final OutputStream httpOut = conn.getOutputStream(); try { buf.writeTo(httpOut, null); } finally { httpOut.close(); } }
private ObjectId insertMergeResult(TemporaryBuffer buf, Attributes attributes) throws IOException { InputStream in = buf.openInputStream(); try (LfsInputStream is = LfsFactory.getInstance().applyCleanFilter( getRepository(), in, buf.length(), attributes.get(Constants.ATTR_MERGE))) { return getObjectInserter().insert(OBJ_BLOB, is.getLength(), is); } }