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

com.godmonth.util.validations.GbkSizeValidator Maven / Gradle / Ivy

There is a newer version: 1.0.2
Show newest version
package com.godmonth.util.validations;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

import org.apache.commons.io.Charsets;

/**
 * @author shenyue
 */
public class GbkSizeValidator implements ConstraintValidator {

	private GbkSize constraintAnnotation;

	@Override
	public void initialize(GbkSize constraintAnnotation) {
		this.constraintAnnotation = constraintAnnotation;
	}

	@Override
	public boolean isValid(String value, ConstraintValidatorContext context) {
		if (value != null) {
			return value.getBytes(Charsets.toCharset("gbk")).length <= constraintAnnotation.max();
		} else {
			return true;
		}
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy