org.yaml.snakeyaml.util.UriEncoder Java Examples

The following examples show how to use org.yaml.snakeyaml.util.UriEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Tag.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
public Tag(String tag) {
    if (tag == null) {
        throw new NullPointerException("Tag must be provided.");
    } else if (tag.length() == 0) {
        throw new IllegalArgumentException("Tag must not be empty.");
    } else if (tag.trim().length() != tag.length()) {
        throw new IllegalArgumentException("Tag must not contain leading or trailing spaces.");
    }
    this.value = UriEncoder.encode(tag);
}
 
Example #2
Source File: ScannerImpl.java    From orion.server with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <p>
 * Scan a sequence of %-escaped URI escape codes and convert them into a
 * String representing the unescaped values.
 * </p>
 * 
 * FIXME This method fails for more than 256 bytes' worth of URI-encoded
 * characters in a row. Is this possible? Is this a use-case?
 * 
 * @see http://www.ietf.org/rfc/rfc2396.txt, section 2.4, Escaped Encoding.
 */
private String scanUriEscapes(String name, Mark startMark) {
    // First, look ahead to see how many URI-escaped characters we should
    // expect, so we can use the correct buffer size.
    int length = 1;
    while (reader.peek(length * 3) == '%') {
        length++;
    }
    // See the specification for details.
    // URIs containing 16 and 32 bit Unicode characters are
    // encoded in UTF-8, and then each octet is written as a
    // separate character.
    Mark beginningMark = reader.getMark();
    ByteBuffer buff = ByteBuffer.allocate(length);
    while (reader.peek() == '%') {
        reader.forward();
        try {
            byte code = (byte) Integer.parseInt(reader.prefix(2), 16);
            buff.put(code);
        } catch (NumberFormatException nfe) {
            throw new ScannerException("while scanning a " + name, startMark,
                    "expected URI escape sequence of 2 hexadecimal numbers, but found "
                            + reader.peek() + "(" + ((int) reader.peek()) + ") and "
                            + reader.peek(1) + "(" + ((int) reader.peek(1)) + ")",
                    reader.getMark());
        }
        reader.forward(2);
    }
    buff.flip();
    try {
        return UriEncoder.decode(buff);
    } catch (CharacterCodingException e) {
        throw new ScannerException("while scanning a " + name, startMark,
                "expected URI in UTF-8: " + e.getMessage(), beginningMark);
    }
}
 
Example #3
Source File: Tag.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
public Tag(String tag) {
    if (tag == null) {
        throw new NullPointerException("Tag must be provided.");
    } else if (tag.length() == 0) {
        throw new IllegalArgumentException("Tag must not be empty.");
    } else if (tag.trim().length() != tag.length()) {
        throw new IllegalArgumentException("Tag must not contain leading or trailing spaces.");
    }
    this.value = UriEncoder.encode(tag);
    this.secondary = !tag.startsWith(PREFIX);
}
 
Example #4
Source File: ScannerImpl.java    From snake-yaml with Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Scan a sequence of %-escaped URI escape codes and convert them into a
 * String representing the unescaped values.
 * </p>
 * 
 * FIXME This method fails for more than 256 bytes' worth of URI-encoded
 * characters in a row. Is this possible? Is this a use-case?
 * 
 * @see <a href="http://www.ietf.org/rfc/rfc2396.txt"></a>, section 2.4, Escaped Encoding.
 */
private String scanUriEscapes(String name, Mark startMark) {
    // First, look ahead to see how many URI-escaped characters we should
    // expect, so we can use the correct buffer size.
    int length = 1;
    while (reader.peek(length * 3) == '%') {
        length++;
    }
    // See the specification for details.
    // URIs containing 16 and 32 bit Unicode characters are
    // encoded in UTF-8, and then each octet is written as a
    // separate character.
    Mark beginningMark = reader.getMark();
    ByteBuffer buff = ByteBuffer.allocate(length);
    while (reader.peek() == '%') {
        reader.forward();
        try {
            byte code = (byte) Integer.parseInt(reader.prefix(2), 16);
            buff.put(code);
        } catch (NumberFormatException nfe) {
            throw new ScannerException("while scanning a " + name, startMark,
                    "expected URI escape sequence of 2 hexadecimal numbers, but found "
                            + reader.peek() + "(" + ((int) reader.peek()) + ") and "
                            + reader.peek(1) + "(" + ((int) reader.peek(1)) + ")",
                    reader.getMark());
        }
        reader.forward(2);
    }
    buff.flip();
    try {
        return UriEncoder.decode(buff);
    } catch (CharacterCodingException e) {
        throw new ScannerException("while scanning a " + name, startMark,
                "expected URI in UTF-8: " + e.getMessage(), beginningMark);
    }
}
 
Example #5
Source File: FtpConnector.java    From StormCV with Apache License 2.0 5 votes vote down vote up
@Override
public void moveTo(String loc) throws IOException{
	try{
		this.location = new URI(UriEncoder.encode(loc));
		checkAndConnect();
		int code = client.cwd(location.getPath());
		if(code == 250) return;
		code = client.cwd(location.getPath().substring(0, location.getPath().lastIndexOf('/')));
	}catch(Exception e){
		logger.warn("Unable to move to "+location+" due to: "+e.getMessage());
		throw new IOException(e);
	}
}
 
Example #6
Source File: Tag.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public Tag(Class<? extends Object> clazz) {
    if (clazz == null) {
        throw new NullPointerException("Class for tag must be provided.");
    }
    this.value = Tag.PREFIX + UriEncoder.encode(clazz.getName());
}
 
Example #7
Source File: Tag.java    From orion.server with Eclipse Public License 1.0 4 votes vote down vote up
public String getClassName() {
    if (!value.startsWith(Tag.PREFIX)) {
        throw new YAMLException("Invalid tag: " + value);
    }
    return UriEncoder.decode(value.substring(Tag.PREFIX.length()));
}
 
Example #8
Source File: Tag.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public Tag(Class<? extends Object> clazz) {
    if (clazz == null) {
        throw new NullPointerException("Class for tag must be provided.");
    }
    this.value = Tag.PREFIX + UriEncoder.encode(clazz.getName());
}
 
Example #9
Source File: Tag.java    From snake-yaml with Apache License 2.0 4 votes vote down vote up
public String getClassName() {
    if (!value.startsWith(Tag.PREFIX)) {
        throw new YAMLException("Invalid tag: " + value);
    }
    return UriEncoder.decode(value.substring(Tag.PREFIX.length()));
}