Beispiel #1
0
	public static String decodeFileName(String name) throws InvalidNameException
	{
		try
		{
			String r = Punycode.decode(name);
			r = r.replace((char)('\ue200' + '.'), '.');
			r = r.replace((char)('\ue200' + '\\'), '\\');
			r = r.replace((char)('\ue200' + '/'), '/');
			r = r.replace((char)('\ue200' + '"'), '"');
			r = r.replace((char)('\ue200' + '<'), '<');
			r = r.replace((char)('\ue200' + '>'), '>');
			r = r.replace((char)('\ue200' + '|'), '|');
			r = r.replace((char)('\ue200' + '?'), '?');
			r = r.replace((char)('\ue200' + '*'), '*');
			r = r.replace((char)('\ue200' + ':'), ':');
			r = r.replace((char)('\ue200' + '-'), '-');
			return r;
		}
		catch (PunycodeException ex)
		{
			throw new InvalidNameException(ex);
		}
	}
Beispiel #2
0
	public static String sanitizeFileName(String name) throws InvalidNameException
	{
		try
		{
			String r = name.toLowerCase(Locale.ENGLISH);
			r = r.replace('.', (char)('\ue200' + '.'));
			r = r.replace('\\', (char)('\ue200' + '\\'));
			r = r.replace('/', (char)('\ue200' + '/'));
			r = r.replace('"', (char)('\ue200' + '"'));
			r = r.replace('<', (char)('\ue200' + '<'));
			r = r.replace('>', (char)('\ue200' + '>'));
			r = r.replace('|', (char)('\ue200' + '|'));
			r = r.replace('?', (char)('\ue200' + '?'));
			r = r.replace('*', (char)('\ue200' + '*'));
			r = r.replace(':', (char)('\ue200' + ':'));
			r = r.replace('-', (char)('\ue200' + '-'));
			r = INVALIDFILECHARS.matcher(r).replaceAll("");
			return Punycode.encode(r);
		}
		catch (PunycodeException ex)
		{
			throw new InvalidNameException(ex);
		}
	}