git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marek Zawirski <marek.zawirski@gmail.com>
To: robin.rosenberg@dewire.com, spearce@spearce.org
Cc: git@vger.kernel.org, Marek Zawirski <marek.zawirski@gmail.com>
Subject: [EGIT PATCH 04/20] WindowedFile fragments copying: copyToStream()
Date: Sun, 15 Jun 2008 23:45:33 +0200	[thread overview]
Message-ID: <1213566349-25395-5-git-send-email-marek.zawirski@gmail.com> (raw)
In-Reply-To: <1213566349-25395-4-git-send-email-marek.zawirski@gmail.com>

Method supports direct rewriting of file segment to the specified output
stream.

Signed-off-by: Marek Zawirski <marek.zawirski@gmail.com>
---
 .../src/org/spearce/jgit/lib/WindowedFile.java     |   43 ++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java
index 323b396..fff8990 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/lib/WindowedFile.java
@@ -40,6 +40,7 @@ package org.spearce.jgit.lib;
 import java.io.EOFException;
 import java.io.File;
 import java.io.IOException;
+import java.io.OutputStream;
 import java.io.RandomAccessFile;
 import java.nio.MappedByteBuffer;
 import java.nio.channels.FileChannel.MapMode;
@@ -195,6 +196,48 @@ public class WindowedFile {
 			throw new EOFException();
 	}
 
+	/**
+	 * Copy the requested number of bytes to the provided output stream.
+	 * <p>
+	 * This routine always reads until either the requested number of bytes has
+	 * been copied or EOF has been reached.
+	 * </p>
+	 * 
+	 * @param position
+	 *            the starting offset, as measured in bytes from the beginning
+	 *            of this file, to copy from.
+	 * @param buf
+	 *            temporary buffer to copy bytes into. In case of a big amount
+	 *            of data to copy, size of at least few kB is recommended. It
+	 *            does not need to be of size <code>cnt</code>, however.
+	 * @param cnt
+	 *            number of bytes to copy. Must not exceed
+	 *            <code>file.length - position</code>.
+	 * @param out
+	 *            output stream where read data is written out. No buffering is
+	 *            guaranteed by this method.
+	 * @param curs
+	 *            current cursor for reading data from the file.
+	 * @throws IOException
+	 *             a necessary window was not found in the window cache and
+	 *             trying to load it in from the operating system failed.
+	 * @throws EOFException
+	 *             the file ended before <code>cnt</code> bytes could be read.
+	 */
+	public void copyToStream(long position, final byte[] buf, long cnt,
+			final OutputStream out, final WindowCursor curs)
+			throws IOException, EOFException {
+		while (cnt > 0) {
+			int toRead = (int) Math.min(cnt, buf.length);
+			int read = read(position, buf, 0, toRead, curs);
+			if (read != toRead)
+				throw new EOFException();
+			position += read;
+			cnt -= read;
+			out.write(buf, 0, read);
+		}
+	}
+
 	void readCompressed(final long position, final byte[] dstbuf,
 			final WindowCursor curs) throws IOException, DataFormatException {
 		final Inflater inf = InflaterCache.get();
-- 
1.5.5.1

  reply	other threads:[~2008-06-15 21:47 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-15 21:45 [EGIT PATCH 00/20] PackWriter, first usable attempt Marek Zawirski
2008-06-15 21:45 ` [EGIT PATCH 01/20] Fix typo in PackIndexV2 Marek Zawirski
2008-06-15 21:45   ` [EGIT PATCH 02/20] Integer versions of copyRawTo() and fromRaw() in ObjectId Marek Zawirski
2008-06-15 21:45     ` [EGIT PATCH 03/20] Add openObjectInAllPacks() to Repository, exposing packed objects storage Marek Zawirski
2008-06-15 21:45       ` Marek Zawirski [this message]
2008-06-15 21:45         ` [EGIT PATCH 05/20] Reverse pack index implementation: PackReverseIndex Marek Zawirski
2008-06-15 21:45           ` [EGIT PATCH 06/20] Tests for PackReverseIndex Marek Zawirski
2008-06-15 21:45             ` [EGIT PATCH 07/20] Refactor PackIndexV2 - extract binarySearchLevelTwo() Marek Zawirski
2008-06-15 21:45               ` [EGIT PATCH 08/20] CRC32 support for PackIndex Marek Zawirski
2008-06-15 21:45                 ` [EGIT PATCH 09/20] CRC32 PackIndex tests Marek Zawirski
2008-06-15 21:45                   ` [EGIT PATCH 10/20] Format PackedObjectLoader class Marek Zawirski
2008-06-15 21:45                     ` [EGIT PATCH 11/20] Format UnpackedObjectLoader class Marek Zawirski
2008-06-15 21:45                       ` [EGIT PATCH 12/20] Format DeltaOfsPackedObjectLoader class Marek Zawirski
2008-06-15 21:45                         ` [EGIT PATCH 13/20] Raw-data operations in ObjectLoaders and PackFile Marek Zawirski
2008-06-15 21:45                           ` [EGIT PATCH 14/20] Add hasRevSort() in RevWalk for faster sorting strategy checking Marek Zawirski
2008-06-15 21:45                             ` [EGIT PATCH 15/20] Refactor getRevSort() calls to hasRevSort() Marek Zawirski
2008-06-15 21:45                               ` [EGIT PATCH 16/20] Support for RevSort.BOUNDARY in ObjectWalk Marek Zawirski
2008-06-15 21:45                                 ` [EGIT PATCH 17/20] Rename confusing objects field " Marek Zawirski
2008-06-15 21:45                                   ` [EGIT PATCH 18/20] New CountingOutputStream class - stream decorator Marek Zawirski
2008-06-15 21:45                                     ` [EGIT PATCH 19/20] Simplified implementation of pack creation: PackWriter Marek Zawirski
2008-06-15 21:45                                       ` [EGIT PATCH 20/20] PackWriter test suite Marek Zawirski
2008-06-17 21:28                                       ` [EGIT PATCH 21/20] Make isBetterDeltaReuseLoader() static in PackWriter Marek Zawirski
2008-06-17 22:07                                         ` Robin Rosenberg
2008-06-19 16:26                                           ` Marek Zawirski
2008-06-16  4:06           ` [EGIT PATCH 05/20] Reverse pack index implementation: PackReverseIndex Shawn O. Pearce
2008-06-16 16:27             ` Marek Zawirski
2008-06-17  2:02               ` Shawn O. Pearce
2008-06-16  5:19 ` [EGIT PATCH 00/20] PackWriter, first usable attempt Shawn O. Pearce
2008-06-16 16:37   ` Marek Zawirski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1213566349-25395-5-git-send-email-marek.zawirski@gmail.com \
    --to=marek.zawirski@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=robin.rosenberg@dewire.com \
    --cc=spearce@spearce.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).