All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.github.wycst.wast.json.AsciiStringSource Maven / Gradle / Ivy

Go to download

Wast is a high-performance Java toolset library package that includes JSON, YAML, CSV, HttpClient, JDBC and EL engines

The newest version!
package io.github.wycst.wast.json;

import io.github.wycst.wast.common.reflect.UnsafeHelper;

final class AsciiStringSource implements CharSource {

    private final String input;
    private final byte[] bytes;

    public AsciiStringSource(String input, byte[] bytes) {
        this.bytes = bytes;
        this.input = input;
    }

    /**
     * 构建对象
     *
     * @param input
     * @param bytes
     * @return
     */
    public static AsciiStringSource of(String input, byte[] bytes) {
        return new AsciiStringSource(input, bytes);
    }

    /**
     * 构建对象
     *
     * @param input
     * @return
     */
    public static AsciiStringSource of(String input) {
        byte[] bytes = (byte[]) UnsafeHelper.getStringValue(input);
        return new AsciiStringSource(input, bytes);
    }

    /**
     * 构建对象
     *
     * @param bytes
     * @return
     */
    public static AsciiStringSource of(byte[] bytes) {
        String input = UnsafeHelper.getAsciiString(bytes);
        return new AsciiStringSource(input, bytes);
    }

    @Override
    public byte[] byteArray() {
        return bytes;
    }

    @Override
    public String input() {
        return input;
    }

    @Override
    public int indexOf(int ch, int beginIndex) {
        return input.indexOf(ch, beginIndex);
    }

    @Override
    public String substring(int beginIndex, int endIndex) {
        return JSONUnsafe.createAsciiString(bytes, beginIndex, endIndex - beginIndex);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy