Here you can find the source of sanitizeIdentifier(String identifier)
Stream identifiers are used to identify the content of a specific stream.
Parameter | Description |
---|---|
identifier | Unfiltered identifier to sanitize |
public static String sanitizeIdentifier(String identifier)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww .j av a 2s . c o m*/ * Sanitizes a stream identifier * <p> * Stream identifiers are used to identify the content of a specific stream. * It is stored in the stream header, just after the constant format identifier. * <p> * If the input identifier is longer than four bytes, it is trimmed to exactly four bytes. * If the input identifier is lesser than four bytes, white spaces are padded to the right up to four bytes. * <p> * The identifier must be composed only of US-ASCII letters and digits. * Any non-compliant character is ignored. * * @param identifier Unfiltered identifier to sanitize * @return the sanitized four-byte identifier */ public static String sanitizeIdentifier(String identifier) { StringBuilder sb = new StringBuilder(); for (int i = 0; i < 4 && i < identifier.length(); i++) { Character c = identifier.charAt(i); if (c.charValue() > 127 || !Character.isLetterOrDigit(c)) continue; sb.append(c); } return String.format("%-4s", sb.toString()); } }