浏览代码

Merge "Fix warnings about assigning paramter in util.io"

tags/v3.0.0.201305080800-m7
Robin Rosenberg 11 年前
父节点
当前提交
9d9cdd780c

+ 10
- 10
org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFInputStream.java 查看文件

/* /*
* Copyright (C) 2012, Robin Rosenberg * Copyright (C) 2012, Robin Rosenberg
* Copyright (C) 2010, Marc Strapetz <marc.strapetz@syntevo.com>
* Copyright (C) 2010, 2013 Marc Strapetz <marc.strapetz@syntevo.com>
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
* This program and the accompanying materials are made available * This program and the accompanying materials are made available
} }


@Override @Override
public int read(byte[] bs, int off, int len) throws IOException {
public int read(byte[] bs, final int off, final int len) throws IOException {
if (len == 0) if (len == 0)
return 0; return 0;


if (cnt == -1) if (cnt == -1)
return -1; return -1;


final int startOff = off;
int i = off;
final int end = off + len; final int end = off + len;


while (off < end) {
while (i < end) {
if (ptr == cnt && !fillBuffer()) if (ptr == cnt && !fillBuffer())
break; break;


byte b = buf[ptr++]; byte b = buf[ptr++];
if (isBinary || b != '\n') { if (isBinary || b != '\n') {
// Logic for binary files ends here // Logic for binary files ends here
bs[off++] = last = b;
bs[i++] = last = b;
continue; continue;
} }


if (b == '\n') { if (b == '\n') {
if (last == '\r') { if (last == '\r') {
bs[off++] = last = b;
bs[i++] = last = b;
continue; continue;
} }
bs[off++] = last = '\r';
bs[i++] = last = '\r';
ptr--; ptr--;
} else } else
bs[off++] = last = b;
bs[i++] = last = b;
} }
int n = startOff == off ? -1 : off - startOff;
int n = i == off ? -1 : i - off;
if (n > 0) if (n > 0)
last = bs[off - 1];
last = bs[i - 1];
return n; return n;
} }



+ 6
- 5
org.eclipse.jgit/src/org/eclipse/jgit/util/io/AutoCRLFOutputStream.java 查看文件

} }


@Override @Override
public void write(byte[] b, int off, int len) throws IOException {
int overflow = buffer(b, off, len);
public void write(byte[] b, final int startOff, final int startLen)
throws IOException {
final int overflow = buffer(b, startOff, startLen);
if (overflow < 0) if (overflow < 0)
return; return;
off = off + len - overflow;
len = overflow;
final int off = startOff + startLen - overflow;
final int len = overflow;
if (len == 0) if (len == 0)
return; return;
int lastw = off; int lastw = off;
return; return;
} }
for (int i = off; i < off + len; ++i) { for (int i = off; i < off + len; ++i) {
byte c = b[i];
final byte c = b[i];
if (c == '\r') { if (c == '\r') {
buf = '\r'; buf = '\r';
} else if (c == '\n') { } else if (c == '\n') {

+ 9
- 9
org.eclipse.jgit/src/org/eclipse/jgit/util/io/EolCanonicalizingInputStream.java 查看文件

/* /*
* Copyright (C) 2010, Marc Strapetz <marc.strapetz@syntevo.com>
* Copyright (C) 2010, 2013 Marc Strapetz <marc.strapetz@syntevo.com>
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
* This program and the accompanying materials are made available * This program and the accompanying materials are made available
} }


@Override @Override
public int read(byte[] bs, int off, int len) throws IOException {
public int read(byte[] bs, final int off, final int len) throws IOException {
if (len == 0) if (len == 0)
return 0; return 0;


if (cnt == -1) if (cnt == -1)
return -1; return -1;


final int startOff = off;
int i = off;
final int end = off + len; final int end = off + len;


while (off < end) {
while (i < end) {
if (ptr == cnt && !fillBuffer()) { if (ptr == cnt && !fillBuffer()) {
break; break;
} }
byte b = buf[ptr++]; byte b = buf[ptr++];
if (isBinary || b != '\r') { if (isBinary || b != '\r') {
// Logic for binary files ends here // Logic for binary files ends here
bs[off++] = b;
bs[i++] = b;
continue; continue;
} }


if (ptr == cnt && !fillBuffer()) { if (ptr == cnt && !fillBuffer()) {
bs[off++] = '\r';
bs[i++] = '\r';
break; break;
} }


if (buf[ptr] == '\n') { if (buf[ptr] == '\n') {
bs[off++] = '\n';
bs[i++] = '\n';
ptr++; ptr++;
} else } else
bs[off++] = '\r';
bs[i++] = '\r';
} }


return startOff == off ? -1 : off - startOff;
return i == off ? -1 : i - off;
} }


@Override @Override

+ 5
- 4
org.eclipse.jgit/src/org/eclipse/jgit/util/io/TeeInputStream.java 查看文件

/* /*
* Copyright (C) 2010, Google Inc.
* Copyright (C) 2010, 2013 Google Inc.
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
* This program and the accompanying materials are made available * This program and the accompanying materials are made available
} }


@Override @Override
public long skip(long cnt) throws IOException {
public long skip(final long count) throws IOException {
long skipped = 0; long skipped = 0;
byte[] b = skipBuffer();
long cnt = count;
final byte[] b = skipBuffer();
while (0 < cnt) { while (0 < cnt) {
int n = src.read(b, 0, (int) Math.min(b.length, cnt));
final int n = src.read(b, 0, (int) Math.min(b.length, cnt));
if (n <= 0) if (n <= 0)
break; break;
dst.write(b, 0, n); dst.write(b, 0, n);

+ 13
- 12
org.eclipse.jgit/src/org/eclipse/jgit/util/io/UnionInputStream.java 查看文件

/* /*
* Copyright (C) 2009, Google Inc.
* Copyright (C) 2009, 2013 Google Inc.
* and other copyright owners as documented in the project's IP log. * and other copyright owners as documented in the project's IP log.
* *
* This program and the accompanying materials are made available * This program and the accompanying materials are made available
} }


@Override @Override
public long skip(long len) throws IOException {
long cnt = 0;
while (0 < len) {
public long skip(final long count) throws IOException {
long skipped = 0;
long cnt = count;
while (0 < cnt) {
final InputStream in = head(); final InputStream in = head();
final long n = in.skip(len);
final long n = in.skip(cnt);
if (0 < n) { if (0 < n) {
cnt += n;
len -= n;
skipped += n;
cnt -= n;


} else if (in == EOF) { } else if (in == EOF) {
return cnt;
return skipped;


} else { } else {
// Is this stream at EOF? We can't tell from skip alone. // Is this stream at EOF? We can't tell from skip alone.
final int r = in.read(); final int r = in.read();
if (r < 0) { if (r < 0) {
pop(); pop();
if (0 < cnt)
if (0 < skipped)
break; break;
} else { } else {
cnt += 1;
len -= 1;
skipped += 1;
cnt -= 1;
} }
} }
} }
return cnt;
return skipped;
} }


@Override @Override

正在加载...
取消
保存