risdenk commented on code in PR #1805: URL: https://github.com/apache/solr/pull/1805#discussion_r1272208331
########## solr/core/src/java/org/apache/solr/util/BinaryUtils.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.solr.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; + +public class BinaryUtils { Review Comment: There is similar code in ``` solr/solrj/src/java/org/apache/solr/client/solrj/impl/BinaryRequestWriter.java:87: public static class BAOS extends ByteArrayOutputStream { ``` Might make sense to use this class there as well? ########## solr/core/src/java/org/apache/solr/util/BinaryUtils.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.solr.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; + +public class BinaryUtils { Review Comment: I think I'd prefer the name `InputStreamUtils` to make it more clear? ########## solr/core/src/java/org/apache/solr/util/BinaryUtils.java: ########## @@ -0,0 +1,60 @@ +/* + * 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.solr.util; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.nio.BufferOverflowException; +import java.nio.ByteBuffer; + +public class BinaryUtils { + + public static class BAOS extends ByteArrayOutputStream { + public ByteBuffer getByteBuffer() { + return ByteBuffer.wrap(super.buf, 0, super.count); + } + } + + public static ByteBuffer inputStreamToByteArray(InputStream is) throws IOException { + return inputStreamToByteArray(is, Integer.MAX_VALUE); + } + + /** + * Reads an input stream into a byte array + * + * @param is the input stream + * @return the byte array + * @throws IOException If there is a low-level I/O error. + */ + public static ByteBuffer inputStreamToByteArray(InputStream is, long maxSize) throws IOException { Review Comment: If this was `InputStreamUtils` class then method could be `toByteArray(...)` I think -- 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: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org