public void assertValidity()

in src/java/org/apache/fulcrum/intake/validator/FileValidator.java [64:108]


    public void assertValidity(Part testValue)
            throws ValidationException
    {
        byte[] fileData = new byte[(int) testValue.getSize()];
        String contentType = testValue.getContentType();
        String charset = Charset.defaultCharset().name();

        if (contentType.contains("charset"))
        {
            Matcher matcher = charsetPattern.matcher(contentType);
            if (matcher.matches())
            {
                charset = matcher.group(1);
            }
        }

        try (InputStream fis = testValue.getInputStream())
        {
            int byteSize = fis.read(fileData);
            if ( fileData.length != byteSize )
            {
            	throw new ValidationException("Byte length mismatch found");
            }
            
        }
        catch (IOException e)
        {
            fileData = null;
        }

        String content = null;
        try
        {
        	if ( fileData != null )
        	{
        		content = new String(fileData, charset);
        	}
        }
        catch (UnsupportedEncodingException e)
        {
            throw new ValidationException("Invalid charset " + charset);
        }

        super.assertValidity(content);
    }