Java Is UTF8 isUTF8StringLengthValid(int min, int max, String string)

Here you can find the source of isUTF8StringLengthValid(int min, int max, String string)

Description

Check the validity of the Length of a UTF8 String.

License

Apache License

Parameter

Parameter Description
min a parameter
max a parameter
string a parameter

Return

boolean indicating UTF-8 String Length is valid or not.

Declaration

public static boolean isUTF8StringLengthValid(int min, int max, String string) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.io.*;

public class Main {
    /**/*from  www.jav a  2s  .com*/
     * Check the validity of the Length of a UTF8 String.
     *
     * @param min
     * @param max
     * @param string
     * @return boolean indicating UTF-8 String Length is valid or not.
     */
    public static boolean isUTF8StringLengthValid(int min, int max, String string) {
        if (string == null) {
            return false;
        }
        try {
            byte[] bytes = string.getBytes("UTF-8");
            return ((bytes.length >= min) && (bytes.length <= max));
        } catch (UnsupportedEncodingException uee) {
            // Ignore...
        }
        return false;
    }
}

Related

  1. isUTF8(File f)
  2. isUTF8Encoding(String path)