image.png

    1. /*
    2. * Licensed to the Apache Software Foundation (ASF) under one
    3. * or more contributor license agreements. See the NOTICE file
    4. * distributed with this work for additional information
    5. * regarding copyright ownership. The ASF licenses this file
    6. * to you under the Apache License, Version 2.0 (the
    7. * "License"); you may not use this file except in compliance
    8. * with the License. You may obtain a copy of the License at
    9. *
    10. * http://www.apache.org/licenses/LICENSE-2.0
    11. *
    12. * Unless required by applicable law or agreed to in writing, software
    13. * distributed under the License is distributed on an "AS IS" BASIS,
    14. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15. * See the License for the specific language governing permissions and
    16. * limitations under the License.
    17. */
    18. package org.apache.flink.core.memory;
    19. import org.apache.flink.annotation.Public;
    20. import java.io.DataInput;
    21. import java.io.IOException;
    22. /**
    23. * This interface defines a view over some memory that can be used to sequentially read the contents of the memory.
    24. * The view is typically backed by one or more {@link org.apache.flink.core.memory.MemorySegment}.
    25. */
    26. @Public
    27. public interface DataInputView extends DataInput {
    28. /**
    29. * Skips {@code numBytes} bytes of memory. In contrast to the {@link #skipBytes(int)} method,
    30. * this method always skips the desired number of bytes or throws an {@link java.io.EOFException}.
    31. *
    32. * @param numBytes The number of bytes to skip.
    33. *
    34. * @throws IOException Thrown, if any I/O related problem occurred such that the input could not
    35. * be advanced to the desired position.
    36. */
    37. void skipBytesToRead(int numBytes) throws IOException;
    38. /**
    39. * Reads up to {@code len} bytes of memory and stores it into {@code b} starting at offset {@code off}.
    40. * It returns the number of read bytes or -1 if there is no more data left.
    41. *
    42. * @param b byte array to store the data to
    43. * @param off offset into byte array
    44. * @param len byte length to read
    45. * @return the number of actually read bytes of -1 if there is no more data left
    46. * @throws IOException
    47. */
    48. int read(byte[] b, int off, int len) throws IOException;
    49. /**
    50. * Tries to fill the given byte array {@code b}. Returns the actually number of read bytes or -1 if there is no
    51. * more data.
    52. *
    53. * @param b byte array to store the data to
    54. * @return the number of read bytes or -1 if there is no more data left
    55. * @throws IOException
    56. */
    57. int read(byte[] b) throws IOException;
    58. }