2 * Copyright (c) 2018 Inocybe Technologies and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.netconf.nettyutil.handler;
10 import java.nio.CharBuffer;
11 import java.nio.charset.CharacterCodingException;
12 import java.nio.charset.CharsetEncoder;
13 import java.nio.charset.CodingErrorAction;
14 import java.nio.charset.StandardCharsets;
15 import org.opendaylight.netconf.util.messages.FramingMechanism;
18 * netconf message part constants as bytes.
20 * @author Thomas Pantelis
22 final class MessageParts {
23 static final byte[] END_OF_MESSAGE;
24 static final byte[] START_OF_CHUNK;
25 static final byte[] END_OF_CHUNK;
28 final var encoder = StandardCharsets.US_ASCII.newEncoder()
29 .onMalformedInput(CodingErrorAction.REPORT)
30 .onUnmappableCharacter(CodingErrorAction.REPORT);
33 END_OF_MESSAGE = getBytes(encoder, FramingMechanism.EOM_STR);
34 START_OF_CHUNK = getBytes(encoder, FramingMechanism.CHUNK_START_STR);
35 END_OF_CHUNK = getBytes(encoder, FramingMechanism.CHUNK_END_STR);
36 } catch (CharacterCodingException e) {
37 throw new ExceptionInInitializerError(e);
41 private MessageParts() {
45 private static byte[] getBytes(final CharsetEncoder encoder, final String str) throws CharacterCodingException {
46 final var buf = encoder.encode(CharBuffer.wrap(str));
47 final var bytes = new byte[buf.remaining()];