aboutsummaryrefslogtreecommitdiffstats
path: root/org.eclipse.jgit/src/org/eclipse/jgit/util/io
diff options
context:
space:
mode:
authorMarc Strapetz <marc.strapetz@syntevo.com>2012-02-21 15:18:08 +0100
committerMarc Strapetz <marc.strapetz@syntevo.com>2012-02-21 15:22:36 +0100
commit7df17e57d4e736336de6b95810daf076e9b7dded (patch)
tree275457600d53cdd8bb55f211c7f0ea6ef9943882 /org.eclipse.jgit/src/org/eclipse/jgit/util/io
parent755dfdb40948f5c1ec79e06bde3b0a78c352f27f (diff)
downloadjgit-7df17e57d4e736336de6b95810daf076e9b7dded.tar.gz
jgit-7df17e57d4e736336de6b95810daf076e9b7dded.zip
EolCanonicalizingInputStream: binary detection should be optional
EolCanonicalizingInputStream may also be used in combination with .gitattributes. If .gitattributes states that a file is of type text, line endings have to be canonicalized even if the actual file content seems to be binary. Change-Id: Ie4ccdfc5cb91fbd55e06f51146cf5c7c84b8e18b
Diffstat (limited to 'org.eclipse.jgit/src/org/eclipse/jgit/util/io')
-rw-r--r--org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java16
1 files changed, 9 insertions, 7 deletions
diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java
index 387d9b82bf..2492393064 100644
--- a/org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java
+++ b/org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java
@@ -49,10 +49,11 @@ import java.io.InputStream;
import org.eclipse.jgit.diff.RawText;
/**
- * An input stream which canonicalizes EOLs bytes on the fly to '\n', unless the
- * first 8000 bytes indicate the stream is binary.
+ * An input stream which canonicalizes EOLs bytes on the fly to '\n'.
*
- * Note: Make sure to apply this InputStream only to text files!
+ * Optionally, a binary check on the first 8000 bytes is performed
+ * and in case of binary files, canonicalization is turned off
+ * (for the complete file).
*/
public class EolCanonicalizingInputStream extends InputStream {
private final byte[] single = new byte[1];
@@ -67,7 +68,7 @@ public class EolCanonicalizingInputStream extends InputStream {
private boolean isBinary;
- private boolean modeDetected;
+ private boolean detectBinary;
/**
* Creates a new InputStream, wrapping the specified stream
@@ -75,8 +76,9 @@ public class EolCanonicalizingInputStream extends InputStream {
* @param in
* raw input stream
*/
- public EolCanonicalizingInputStream(InputStream in) {
+ public EolCanonicalizingInputStream(InputStream in, boolean detectBinary) {
this.in = in;
+ this.detectBinary = detectBinary;
}
@Override
@@ -132,9 +134,9 @@ public class EolCanonicalizingInputStream extends InputStream {
cnt = in.read(buf, 0, buf.length);
if (cnt < 1)
return false;
- if (!modeDetected) {
+ if (detectBinary) {
isBinary = RawText.isBinary(buf, cnt);
- modeDetected = true;
+ detectBinary = false;
}
ptr = 0;
return true;