2 * Copyright 2023 PANTHEON.tech, s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package io.atomix.utils.serializer;
18 import static java.util.Objects.requireNonNull;
20 import com.esotericsoftware.kryo.Kryo;
21 import com.esotericsoftware.kryo.KryoException;
22 import com.esotericsoftware.kryo.io.Output;
23 import com.esotericsoftware.kryo.serializers.JavaSerializer;
24 import io.atomix.storage.journal.JournalSerdes.EntryOutput;
25 import java.io.IOException;
27 final class KryoEntryOutput implements EntryOutput {
28 private final Kryo kryo;
29 private final Output output;
30 private final JavaSerializer javaSerializer;
32 KryoEntryOutput(final Kryo kryo, final Output output, final JavaSerializer javaSerializer) {
33 this.kryo = requireNonNull(kryo);
34 this.output = requireNonNull(output);
35 this.javaSerializer = requireNonNull(javaSerializer);
39 public void writeBytes(final byte[] bytes) throws IOException {
41 output.writeBytes(bytes);
42 } catch (KryoException e) {
43 throw new IOException(e);
48 public void writeLong(final long value) throws IOException {
50 output.writeLong(value, false);
51 } catch (KryoException e) {
52 throw new IOException(e);
57 public void writeObject(final Object value) throws IOException {
59 javaSerializer.write(kryo, output, value);
60 } catch (KryoException e) {
61 throw new IOException(e);
66 public void writeString(final String value) throws IOException {
68 output.writeString(value);
69 } catch (KryoException e) {
70 throw new IOException(e);
75 public void writeVarInt(final int value) throws IOException {
77 output.writeVarInt(value, true);
78 } catch (KryoException e) {
79 throw new IOException(e);