Skip to content

Commit

Permalink
src: don't use com.google.common.io.ByteStreams
Browse files Browse the repository at this point in the history
Motivation:
Since Java 9 all methods that used bu dCache from ByteStreams utility class have
an equivalent methods in java.io.InputStream class.

Modification:
Update the usages of com.google.common.io.ByteStreams with alternatives
from java.io.InputStream.

Result:
No visible changes. Less dependency on external libraries.

Acked-by: Lea Morschel
Target: master
Require-book: no
Require-notes: no
  • Loading branch information
kofemann committed Sep 7, 2021
1 parent 4b6338f commit c756308
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.google.common.base.Throwables;
import com.google.common.collect.Lists;
import com.google.common.io.ByteStreams;
import com.google.common.primitives.Ints;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -1060,10 +1059,10 @@ Map<String,byte[]> getAllTags(FsInode inode) {
},
rs -> {
try (InputStream in = rs.getBinaryStream("ivalue")) {
byte[] data = new byte[Ints.saturatedCast(rs.getLong("isize"))];

// we get null if filed id NULL, e.g not set
if (in != null) {
ByteStreams.readFully(in, data);
byte[] data = in.readNBytes(Ints.saturatedCast(rs.getLong("isize")));
tags.put(rs.getString("itagname"), data);
}
} catch (IOException e) {
Expand Down Expand Up @@ -1337,7 +1336,7 @@ int getTag(FsInode inode, String tagName, byte[] data, int offset, int len) {
/* some databases (hsqldb in particular) fill a full record for
* BLOBs and on read reads a full record, which is not what we expect.
*/
return ByteStreams.read(in, data, offset, Math.min(len, (int) rs.getLong("isize")));
return in.readNBytes(data, offset, Math.min(len, (int) rs.getLong("isize")));
} catch (IOException e) {
throw new LobRetrievalFailureException(e.getMessage(), e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Strings.padStart;
import static com.google.common.io.ByteStreams.toByteArray;
import static dmg.util.CommandException.checkCommand;
import static java.util.stream.Collectors.toList;
import static org.dcache.chimera.FileSystemProvider.StatCacheOption.STAT;
Expand Down Expand Up @@ -789,7 +788,7 @@ public Serializable call() throws IOException
* return.
*/
byte[] bytes = (data == null)
? toByteArray(console.getInput())
? console.getInput().readAllBytes()
: newLineTerminated(data).getBytes();
if (bytes.length > 0) {
fs.setTag(inode, tag, bytes, 0, bytes.length);
Expand Down Expand Up @@ -984,7 +983,7 @@ public class WriteDataCommand implements Callable<Serializable>
public Serializable call() throws IOException
{
byte[] bytes = data == null
? toByteArray(System.in)
? System.in.readAllBytes()
: newLineTerminated(data).getBytes();
writeDataIntoFile(bytes);
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.google.common.collect.Maps;
import com.google.common.collect.Range;
import com.google.common.collect.Sets;
import com.google.common.io.ByteStreams;
import com.google.common.net.InetAddresses;
import com.google.common.net.MediaType;
import io.milton.http.FileItem;
Expand Down Expand Up @@ -1696,7 +1695,7 @@ public void relayData(OutputStream outputStream, io.milton.http.Range range)
.getInputStream()) {
setStatus("Mover " + getPool() + "/" + getMoverId() +
": Sending data");
ByteStreams.copy(inputStream, outputStream);
inputStream.transferTo(outputStream);
outputStream.flush();
}

Expand Down Expand Up @@ -1834,7 +1833,7 @@ public void relayData(InputStream inputStream)
setStatus("Mover " + getPool() + "/" + getMoverId() +
": Receiving data");
try {
ByteStreams.copy(inputStream, outputStream);
inputStream.transferTo(outputStream);
outputStream.flush();
} catch (IOException e) {
// Although we were unable to send all the data,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.dcache.pool.p2p;

import com.google.common.io.ByteStreams;
import com.google.common.util.concurrent.FutureCallback;
import com.google.common.util.concurrent.Futures;
import dmg.cells.nucleus.CDC;
Expand Down Expand Up @@ -361,7 +360,7 @@ private Set<Checksum> copy(String uri, ReplicaDescriptor handle) throws IOExcept
throw new EOFException("Received file does not match expected file size.");
}

ByteStreams.copy(entity.getContent(), Channels.newOutputStream(channel));
entity.getContent().transferTo(Channels.newOutputStream(channel));

try {
channel.sync();
Expand Down

0 comments on commit c756308

Please sign in to comment.