forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-10028][core] Introduce reusable ByteArrayData[Input/Output]Vie…
…w as adapter between Data[Input/Output]View and byte-arrays
- Loading branch information
1 parent
a20fd1d
commit fffd2e8
Showing
5 changed files
with
145 additions
and
36 deletions.
There are no files selected for viewing
56 changes: 56 additions & 0 deletions
56
flink-core/src/main/java/org/apache/flink/core/memory/ByteArrayDataInputView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
/* | ||
* 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:https://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.flink.core.memory; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Reusable adapter to {@link DataInputView} that operates on given byte-arrays. | ||
*/ | ||
public class ByteArrayDataInputView extends DataInputViewStreamWrapper { | ||
|
||
@Nonnull | ||
private final ByteArrayInputStreamWithPos inStreamWithPos; | ||
|
||
public ByteArrayDataInputView() { | ||
super(new ByteArrayInputStreamWithPos()); | ||
this.inStreamWithPos = (ByteArrayInputStreamWithPos) in; | ||
} | ||
|
||
public ByteArrayDataInputView(@Nonnull byte[] buffer) { | ||
this(buffer, 0, buffer.length); | ||
} | ||
|
||
public ByteArrayDataInputView(@Nonnull byte[] buffer, int offset, int length) { | ||
this(); | ||
setData(buffer, offset, length); | ||
} | ||
|
||
public int getPosition() { | ||
return inStreamWithPos.getPosition(); | ||
} | ||
|
||
public void setPosition(int pos) { | ||
inStreamWithPos.setPosition(pos); | ||
} | ||
|
||
public void setData(@Nonnull byte[] buffer, int offset, int length) { | ||
inStreamWithPos.setBuffer(buffer, offset, length); | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
flink-core/src/main/java/org/apache/flink/core/memory/ByteArrayDataOutputView.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
* 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:https://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.flink.core.memory; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
/** | ||
* Adapter to {@link DataOutputView} that operates on a byte-array and offers read/write access to the current position. | ||
*/ | ||
public class ByteArrayDataOutputView extends DataOutputViewStreamWrapper { | ||
|
||
@Nonnull | ||
private final ByteArrayOutputStreamWithPos outputStreamWithPos; | ||
|
||
public ByteArrayDataOutputView() { | ||
this(64); | ||
} | ||
|
||
public ByteArrayDataOutputView(int initialSize) { | ||
super(new ByteArrayOutputStreamWithPos(initialSize)); | ||
this.outputStreamWithPos = (ByteArrayOutputStreamWithPos) out; | ||
} | ||
|
||
public void reset() { | ||
outputStreamWithPos.reset(); | ||
} | ||
|
||
@Nonnull | ||
public byte[] toByteArray() { | ||
return outputStreamWithPos.toByteArray(); | ||
} | ||
|
||
public int getPosition() { | ||
return outputStreamWithPos.getPosition(); | ||
} | ||
|
||
public void setPosition(int position) { | ||
outputStreamWithPos.setPosition(position); | ||
} | ||
|
||
@Nonnull | ||
public byte[] getInternalBufferReference() { | ||
return outputStreamWithPos.getBuf(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters