kbendick commented on code in PR #4534: URL: https://github.com/apache/iceberg/pull/4534#discussion_r851389075
########## core/src/test/java/org/apache/iceberg/io/InMemoryInputFile.java: ########## @@ -0,0 +1,131 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.apache.iceberg.io; + +import java.io.ByteArrayInputStream; +import java.io.IOException; +import java.util.UUID; +import org.apache.iceberg.relocated.com.google.common.base.Preconditions; + +public class InMemoryInputFile implements InputFile { + + private final String location; + private final byte[] contents; + + public InMemoryInputFile(byte[] contents) { + this("memory:" + UUID.randomUUID(), contents); + } + + public InMemoryInputFile(String location, byte[] contents) { + Preconditions.checkNotNull(location, "location is null"); + Preconditions.checkNotNull(contents, "contents is null"); + this.location = location; + this.contents = contents.clone(); + } Review Comment: As a side note: Typically we use `ByteBuffer`s instead of raw `byte[]`, so that we can get views over slices etc for free and help avoid additional allocations in many situations. ByteBuffers also have the advantage of presenting views over type-specific byte arrays (for `char`, `int`, `float`, etc). And these views are indexed in terms of the type-specific size of the values, which is easier to reason about. The type-specific views also offer direct access to the backing byte buffer as well as bulk get and put methods for transferring large contiguous sequences of values. This is test code, but if we were to ever move this to be code used in the project, we'd almost certainly want to use `ByteBuffer` instead of the raw `byte[]` throughout where possible. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
