Subversion Repository Public Repository

litesoft

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
27
28
29
30
package org.litesoft.sandbox.csapp.server;

import java.io.*;

public class SmallFileValidatorOnlyDisplayable7BitAscii implements SmallFileValidator
{
    public static final SmallFileValidator INSTANCE = new SmallFileValidatorOnlyDisplayable7BitAscii();

    @Override
    public AcceptedResult validate( String fileName, byte[] contents )
            throws UnsupportedEncodingException
    {
        String text = new String( contents, "UTF-8" );

        for ( int i = 0; i < text.length(); i++ )
        {
            char c = text.charAt( i );
            if ( (' ' <= c) && (c <= 126) )
            {
                continue;
            }
            if ( c == '\r' || c == '\n' )
            {
                continue;
            }
            throw new UnsupportedEncodingException( "Only Supporting a limited subset of 7-bit Ascii" );
        }
        return new AcceptedResult( fileName, "Accepted: " + fileName, text );
    }
}

Commits for litesoft/trunk/GWT_Sandbox/Upload/src/org/litesoft/sandbox/csapp/server/SmallFileValidatorOnlyDisplayable7BitAscii.java

Diff revisions: vs.
Revision Author Commited Message
522 GeorgeS picture GeorgeS Tue 27 Sep, 2011 18:31:40 +0000

Upload Widget...