// Path: library/src/main/java/uk/co/alt236/easycursor/exceptions/ConversionErrorException.java
// public class ConversionErrorException extends RuntimeException {
//     public ConversionErrorException(final String message) {
//         super(message);
//     }
// 
//     public ConversionErrorException(final Exception exception) {
//         super(exception);
//     }
// }


import uk.co.alt236.easycursor.exceptions.ConversionErrorException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
/*
 * ***************************************************************************
 * Copyright 2015 Alexandros Schillings
 * <p>
 * Licensed 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 uk.co.alt236.easycursor.internal.conversion;



public final class ObjectConverter {
    private static final int INT_BYTE_SIZE = 4;
    private static final int LONG_BYTE_SIZE = 8;
    private static final int FLOAT_BYTE_SIZE = 4;
    private static final int DOUBLE_BYTE_SIZE = 8;
    private static final int SHORT_BYTE_SIZE = 2;

    private static final String UTF_8 = "UTF-8";

    private final String mEncoding;
    private final ByteOrder mByteOrder;

    public ObjectConverter() {
        this(UTF_8, ByteOrder.BIG_ENDIAN);
    }

    public ObjectConverter(final String encoding, final ByteOrder byteOrder) {
        mEncoding = encoding;
        mByteOrder = byteOrder;
    }

    private ByteBuffer getByteBuffer(final int size) {
        return ByteBuffer.allocate(size).order(mByteOrder);
    }

    private byte[] getBytes(final String string) {
        try {
            return string.getBytes(mEncoding);
        } catch (final UnsupportedEncodingException e) {
// Path: library/src/main/java/uk/co/alt236/easycursor/exceptions/ConversionErrorException.java
// public class ConversionErrorException extends RuntimeException {
//     public ConversionErrorException(final String message) {
//         super(message);
//     }
// 
//     public ConversionErrorException(final Exception exception) {
//         super(exception);
//     }
// }


// Path: library/src/main/java/uk/co/alt236/easycursor/internal/conversion/ObjectConverter.java
import uk.co.alt236.easycursor.exceptions.ConversionErrorException;
import java.io.UnsupportedEncodingException;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;

/*
 * ***************************************************************************
 * Copyright 2015 Alexandros Schillings
 * <p>
 * Licensed 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
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * 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 uk.co.alt236.easycursor.internal.conversion;



public final class ObjectConverter {
    private static final int INT_BYTE_SIZE = 4;
    private static final int LONG_BYTE_SIZE = 8;
    private static final int FLOAT_BYTE_SIZE = 4;
    private static final int DOUBLE_BYTE_SIZE = 8;
    private static final int SHORT_BYTE_SIZE = 2;

    private static final String UTF_8 = "UTF-8";

    private final String mEncoding;
    private final ByteOrder mByteOrder;

    public ObjectConverter() {
        this(UTF_8, ByteOrder.BIG_ENDIAN);
    }

    public ObjectConverter(final String encoding, final ByteOrder byteOrder) {
        mEncoding = encoding;
        mByteOrder = byteOrder;
    }

    private ByteBuffer getByteBuffer(final int size) {
        return ByteBuffer.allocate(size).order(mByteOrder);
    }

    private byte[] getBytes(final String string) {
        try {
            return string.getBytes(mEncoding);
        } catch (final UnsupportedEncodingException e) {
            throw new ConversionErrorException(e);