keksmd commented on code in PR #960: URL: https://github.com/apache/incubator-graphar/pull/960#discussion_r3832722654
########## maven-projects/storage-local/src/main/java/org/apache/graphar/storage/local/LocalPositionOutput.java: ########## @@ -0,0 +1,74 @@ +/* + * 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.graphar.storage.local; + +import java.io.IOException; +import java.io.OutputStream; +import java.nio.ByteBuffer; +import org.apache.graphar.storage.PositionOutput; + +final class LocalPositionOutput implements PositionOutput { + private static final int BUFFER_SIZE = 8192; + + private final OutputStream output; + private long position; + + LocalPositionOutput(OutputStream output) { + this.output = output; + } + + @Override + public long position() { + return position; + } + + @Override + public void write(ByteBuffer source) throws IOException { + if (source.hasArray()) { + int length = source.remaining(); + write(source.array(), source.arrayOffset() + source.position(), length); + source.position(source.position() + length); + return; + } + + byte[] buffer = new byte[Math.min(source.remaining(), BUFFER_SIZE)]; Review Comment: Done in 3dde49e. The staging array is now one instance field, allocated on first use so an output that only ever sees heap-backed buffers never pays for it. While writing it I found the direct-buffer path had no test that crossed a chunk boundary (the existing one wrote 2 bytes), so I added one for a 20000-byte direct buffer. With the copy loop reduced to a single pass it fails with `expected:<20000> but was:<8192>`, so it does hold the loop down. -- 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]
