mirror of
https://github.com/elastic/logstash.git
synced 2025-06-28 09:46:03 -04:00
parent
79c0446bf0
commit
f14d550c6a
3 changed files with 13 additions and 61 deletions
|
@ -24,7 +24,7 @@ public class InputStreamStreamInput extends StreamInput {
|
|||
public void readBytes(byte[] b, int offset, int len) throws IOException {
|
||||
if (len < 0)
|
||||
throw new IndexOutOfBoundsException();
|
||||
final int read = Streams.readFully(is, b, offset, len);
|
||||
final int read = readFully(is, b, offset, len);
|
||||
if (read != len) {
|
||||
throw new EOFException();
|
||||
}
|
||||
|
@ -74,4 +74,16 @@ public class InputStreamStreamInput extends StreamInput {
|
|||
public long skip(long n) throws IOException {
|
||||
return is.skip(n);
|
||||
}
|
||||
|
||||
private static int readFully(InputStream reader, byte[] dest, int offset, int len) throws IOException {
|
||||
int read = 0;
|
||||
while (read < len) {
|
||||
final int r = reader.read(dest, offset + read, len - read);
|
||||
if (r == -1) {
|
||||
break;
|
||||
}
|
||||
read += r;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
/*
|
||||
* Licensed to Elasticsearch under one or more contributor
|
||||
* license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright
|
||||
* ownership. Elasticsearch licenses this file to you under
|
||||
* the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
package org.logstash.common.io;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.Reader;
|
||||
|
||||
public abstract class Streams {
|
||||
|
||||
public static int readFully(Reader reader, char[] dest) throws IOException {
|
||||
return readFully(reader, dest, 0, dest.length);
|
||||
}
|
||||
|
||||
public static int readFully(Reader reader, char[] dest, int offset, int len) throws IOException {
|
||||
int read = 0;
|
||||
while (read < len) {
|
||||
final int r = reader.read(dest, offset + read, len - read);
|
||||
if (r == -1) {
|
||||
break;
|
||||
}
|
||||
read += r;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
|
||||
public static int readFully(InputStream reader, byte[] dest) throws IOException {
|
||||
return readFully(reader, dest, 0, dest.length);
|
||||
}
|
||||
|
||||
public static int readFully(InputStream reader, byte[] dest, int offset, int len) throws IOException {
|
||||
int read = 0;
|
||||
while (read < len) {
|
||||
final int r = reader.read(dest, offset + read, len - read);
|
||||
if (r == -1) {
|
||||
break;
|
||||
}
|
||||
read += r;
|
||||
}
|
||||
return read;
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue