aboutsummaryrefslogtreecommitdiffstats
path: root/linguistics/src/main/java/com/yahoo/language/detect/AbstractDetector.java
blob: 9abbf477584a1b02acc5be81b4147fbdc8c9763a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.language.detect;

import com.yahoo.text.Utf8;

import java.nio.ByteBuffer;

/**
 * @author Simon Thoresen Hult
 */
public abstract class AbstractDetector implements Detector {

    @Override
    public final Detection detect(String input, Hint hint) {
        byte[] buf = Utf8.toBytes(input);
        return detect(buf, 0, buf.length, hint);
    }

    @Override
    public final Detection detect(ByteBuffer input, Hint hint) {
        byte[] buf = new byte[input.remaining()];
        input.get(buf, 0, buf.length);
        return detect(buf, 0, buf.length, hint);
    }

}