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

This commit is contained in:
Robin Rosenberg 2013-05-02 17:19:38 -04:00 committed by Gerrit Code Review @ Eclipse.org
commit 9d9cdd780c
5 changed files with 43 additions and 40 deletions

View File

@ -1,6 +1,6 @@
/* /*
* 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
@ -98,40 +98,40 @@ public int read() throws IOException {
} }
@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;
} }

View File

@ -90,12 +90,13 @@ public void write(byte[] b) throws IOException {
} }
@Override @Override
public void write(byte[] b, int off, int len) throws IOException { public void write(byte[] b, final int startOff, final int startLen)
int overflow = buffer(b, off, len); throws IOException {
final int overflow = buffer(b, startOff, startLen);
if (overflow < 0) if (overflow < 0)
return; return;
off = off + len - overflow; final int off = startOff + startLen - overflow;
len = overflow; final int len = overflow;
if (len == 0) if (len == 0)
return; return;
int lastw = off; int lastw = off;
@ -104,7 +105,7 @@ public void write(byte[] b, int off, int len) throws IOException {
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') {

View File

@ -1,5 +1,5 @@
/* /*
* 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
@ -91,17 +91,17 @@ public int read() throws IOException {
} }
@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;
} }
@ -109,23 +109,23 @@ public int read(byte[] bs, int off, int len) throws IOException {
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

View File

@ -1,5 +1,5 @@
/* /*
* 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
@ -89,11 +89,12 @@ public int read() throws IOException {
} }
@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);

View File

@ -1,5 +1,5 @@
/* /*
* 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
@ -158,17 +158,18 @@ public int available() throws IOException {
} }
@Override @Override
public long skip(long len) throws IOException { public long skip(final long count) throws IOException {
long cnt = 0; long skipped = 0;
while (0 < len) { 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; skipped += n;
len -= 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.
@ -178,15 +179,15 @@ public long skip(long len) throws IOException {
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; skipped += 1;
len -= 1; cnt -= 1;
} }
} }
} }
return cnt; return skipped;
} }
@Override @Override