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

org.owasp.esapi.codecs.AbstractIntegerCodec Maven / Gradle / Ivy

/**
 * OWASP Enterprise Security API (ESAPI)
 * 
 * This file is part of the Open Web Application Security Project (OWASP)
 * Enterprise Security API (ESAPI) project. For details, please see
 * http://www.owasp.org/index.php/ESAPI.
 *
 * Copyright (c) 2017 - The OWASP Foundation
 * 
 * The ESAPI is published by OWASP under the BSD license. You should read and accept the
 * LICENSE before you use, modify, and/or redistribute this software.
 * 
 * @author Matt Seil (mseil .at. owasp.org)
 * @created 2017
 * 
 * @author Jeff Williams (jeff.williams .at. aspectsecurity.com) Aspect Security
 * @created 2007
 */
package org.owasp.esapi.codecs;

/**
 * This class is intended to be an alternative Abstract Implementation for parsing encoding
 * data by focusing on {@code int} as opposed to {@code Character}.  Because non-BMP code
 * points cannot be represented by a {@code char}, this class remedies that by parsing string
 * data as codePoints as opposed to a stream of {@code char}s.
 * 
 * @author Matt Seil (mseil .at. owasp.org)
 * @since 2017 -- Adapted from Jeff Williams' original {@code Codec} class.  
 */
public class AbstractIntegerCodec extends AbstractCodec {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public String decode(String input) {
		StringBuilder sb = new StringBuilder();
		PushbackSequence pbs = new PushBackSequenceImpl(input);
		while (pbs.hasNext()) {
			Integer c = decodeCharacter(pbs);
			if (c != null && Character.isValidCodePoint(c)) {
				sb.appendCodePoint(c);
			} else {
				sb.appendCodePoint(pbs.next());
			}
		}
		return sb.toString();
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy