Java Code Examples for java.nio.charset.IllegalCharsetNameException#getLocalizedMessage()

The following examples show how to use java.nio.charset.IllegalCharsetNameException#getLocalizedMessage() . 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: Server.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.perforce.p4java.server.IServer#setCharsetName(java.lang.String)
 */
public boolean setCharsetName(String charsetName) throws UnsupportedCharsetException {
	if (charsetName != null) {
		// Check if it is a supported Perforce charset
		if (!PerforceCharsets.isSupported(charsetName)) {	 
			throw new UnsupportedCharsetException(charsetName);
		}
		// Get the Java equivalent charset for this Perforce charset
		String javaCharsetName = PerforceCharsets.getJavaCharsetName(charsetName);
		if (javaCharsetName != null) {
			try {
				this.charset = Charset.forName(javaCharsetName);
			} catch (UnsupportedCharsetException uce) {
				// In case P4Java's Perforce extended charsets are not
				// loaded in the VM's bootstrap classpath (i.e. P4Java JAR
				// file is inside a WAR deployed in a web app container like
				// Jetty, Tomcat, etc.), we'll instantiate it and lookup the
				// Perforce extended charsets.
				PerforceCharsetProvider p4CharsetProvider = new PerforceCharsetProvider();
				this.charset = p4CharsetProvider.charsetForName(javaCharsetName);
	
				// Throw the unsupported charset exception that was catched.
				if (this.charset == null) {
					throw uce;
				}
			} catch (IllegalCharsetNameException icne) {
				// Throw a unsupported charset exception wrapped around
				// the illegal charset name exception.
				throw new UnsupportedCharsetException(icne.getLocalizedMessage());
			}
			// Set the new charset name
			this.charsetName = charsetName;
		}
	} else { // Reset the charset to "no charset"
		this.charsetName = null;
		this.charset = null;
	}
	
	return (this.charset != null);
}
 
Example 2
Source File: Server.java    From p4ic4idea with Apache License 2.0 5 votes vote down vote up
/**
 * @see com.perforce.p4java.server.IServer#setCharsetName(java.lang.String)
 */
public boolean setCharsetName(String charsetName) throws UnsupportedCharsetException {
	if (charsetName != null) {
		// Check if it is a supported Perforce charset
		if (!PerforceCharsets.isSupported(charsetName)) {	 
			throw new UnsupportedCharsetException(charsetName);
		}
		// Get the Java equivalent charset for this Perforce charset
		String javaCharsetName = PerforceCharsets.getJavaCharsetName(charsetName);
		if (javaCharsetName != null) {
			try {
				this.charset = Charset.forName(javaCharsetName);
			} catch (UnsupportedCharsetException uce) {
				// In case P4Java's Perforce extended charsets are not
				// loaded in the VM's bootstrap classpath (i.e. P4Java JAR
				// file is inside a WAR deployed in a web app container like
				// Jetty, Tomcat, etc.), we'll instantiate it and lookup the
				// Perforce extended charsets.
				PerforceCharsetProvider p4CharsetProvider = new PerforceCharsetProvider();
				this.charset = p4CharsetProvider.charsetForName(javaCharsetName);
	
				// Throw the unsupported charset exception that was catched.
				if (this.charset == null) {
					throw uce;
				}
			} catch (IllegalCharsetNameException icne) {
				// Throw a unsupported charset exception wrapped around
				// the illegal charset name exception.
				throw new UnsupportedCharsetException(icne.getLocalizedMessage());
			}
			// Set the new charset name
			this.charsetName = charsetName;
		}
	} else { // Reset the charset to "no charset"
		this.charsetName = null;
		this.charset = null;
	}
	
	return (this.charset != null);
}
 
Example 3
Source File: Server.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public boolean setCharsetName(final String charsetName) throws UnsupportedCharsetException {
	// "auto" (Guess a P4CHARSET based on client OS params)
	// "none" (same as unsetting P4CHARSET)
	if (isNotBlank(charsetName)
			&& (!"none".equals(charsetName) || !"auto".equals(charsetName))) {
		// Check if it is a supported Perforce charset
		if (!isSupported(charsetName)) {
			throw new UnsupportedCharsetException(charsetName);
		}
		// Get the Java equivalent charset for this Perforce charset
		String javaCharsetName = getJavaCharsetName(charsetName);
		if (isNotBlank(javaCharsetName)) {
			try {
				charset = Charset.forName(javaCharsetName);
			} catch (UnsupportedCharsetException uce) {
				// In case P4Java's Perforce extended charsets are not
				// loaded in the VM's bootstrap classpath (i.e. P4Java JAR
				// file is inside a WAR deployed in a web app container like
				// Jetty, Tomcat, etc.), we'll instantiate it and lookup the
				// Perforce extended charsets.
				PerforceCharsetProvider p4CharsetProvider = new PerforceCharsetProvider();
				charset = p4CharsetProvider.charsetForName(javaCharsetName);

				// Throw the unsupported charset exception that was catched.
				if (nonNull(charset)) {
					throw uce;
				}
			} catch (IllegalCharsetNameException icne) {
				// Throw a unsupported charset exception wrapped around
				// the illegal charset name exception.
				throw new UnsupportedCharsetException(icne.getLocalizedMessage());
			}
			// Set the new charset name
			this.charsetName = charsetName;
		}
	} else { // Reset the charset to "no charset"
		this.charsetName = null;
		charset = null;
	}

	return nonNull(charset);
}
 
Example 4
Source File: Server.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
@Override
public boolean setCharsetName(final String charsetName) throws UnsupportedCharsetException {
	// "auto" (Guess a P4CHARSET based on client OS params)
	// "none" (same as unsetting P4CHARSET)
	if (isNotBlank(charsetName)
			&& !("none".equals(charsetName) || "auto".equals(charsetName))) {
		// Check if it is a supported Perforce charset
		if (!isSupported(charsetName)) {
			throw new UnsupportedCharsetException(charsetName);
		}
		// Get the Java equivalent charset for this Perforce charset
		String javaCharsetName = getJavaCharsetName(charsetName);
		if (isNotBlank(javaCharsetName)) {
			try {
				charset = Charset.forName(javaCharsetName);
			} catch (UnsupportedCharsetException uce) {
				// In case P4Java's Perforce extended charsets are not
				// loaded in the VM's bootstrap classpath (i.e. P4Java JAR
				// file is inside a WAR deployed in a web app container like
				// Jetty, Tomcat, etc.), we'll instantiate it and lookup the
				// Perforce extended charsets.
				PerforceCharsetProvider p4CharsetProvider = new PerforceCharsetProvider();
				charset = p4CharsetProvider.charsetForName(javaCharsetName);

				// Throw the unsupported charset exception that was catched.
				if (isNull(charset)) {
					throw uce;
				}
			} catch (IllegalCharsetNameException icne) {
				// Throw a unsupported charset exception wrapped around
				// the illegal charset name exception.
				throw new UnsupportedCharsetException(icne.getLocalizedMessage());
			}
			// Set the new charset name
			this.charsetName = charsetName;
		}
	} else { // Reset the charset to "no charset"
		this.charsetName = null;
		charset = null;
	}

	return nonNull(charset);
}
 
Example 5
Source File: P4Charset.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
private void setCharsetName(final String charsetName) throws UnsupportedCharsetException {
	// "auto" (Guess a P4CHARSET based on client OS params)
	// "none" (same as unsetting P4CHARSET)
	if (isNotBlank(charsetName)
			&& !("none".equals(charsetName) || "auto".equals(charsetName))) {
		// Check if it is a supported Perforce charset
		if (!isSupported(charsetName)) {
			throw new UnsupportedCharsetException(charsetName);
		}
		// Get the Java equivalent charset for this Perforce charset
		String javaCharsetName = getJavaCharsetName(charsetName);
		if (isNotBlank(javaCharsetName)) {
			try {
				this.charset = Charset.forName(javaCharsetName);
				this.clientBOM = hasClientBOM(charsetName);
			} catch (UnsupportedCharsetException uce) {
				// In case P4Java's Perforce extended charsets are not
				// loaded in the VM's bootstrap classpath (i.e. P4Java JAR
				// file is inside a WAR deployed in a web app container like
				// Jetty, Tomcat, etc.), we'll instantiate it and lookup the
				// Perforce extended charsets.
				PerforceCharsetProvider p4CharsetProvider = new PerforceCharsetProvider();
				this.charset = p4CharsetProvider.charsetForName(javaCharsetName);
				this.clientBOM = false;

				// Throw the unsupported charset exception that was catched.
				if (isNull(this.charset)) {
					throw uce;
				}
			} catch (IllegalCharsetNameException icne) {
				// Throw a unsupported charset exception wrapped around
				// the illegal charset name exception.
				throw new UnsupportedCharsetException(icne.getLocalizedMessage());
			}
			// Set the new charset name
			this.charsetName = charsetName;
		}
	} else { // Reset the charset to "no charset"
		this.charsetName = null;
		this.charset = null;
		this.clientBOM = false;
	}
}
 
Example 6
Source File: P4Charset.java    From p4ic4idea with Apache License 2.0 4 votes vote down vote up
private void setCharsetName(final String charsetName) throws UnsupportedCharsetException {
	// "auto" (Guess a P4CHARSET based on client OS params)
	// "none" (same as unsetting P4CHARSET)
	if (isNotBlank(charsetName)
			&& !("none".equals(charsetName) || "auto".equals(charsetName))) {
		// Check if it is a supported Perforce charset
		if (!isSupported(charsetName)) {
			throw new UnsupportedCharsetException(charsetName);
		}
		// Get the Java equivalent charset for this Perforce charset
		String javaCharsetName = getJavaCharsetName(charsetName);
		if (isNotBlank(javaCharsetName)) {
			try {
				this.charset = Charset.forName(javaCharsetName);
				this.clientBOM = hasClientBOM(charsetName);
			} catch (UnsupportedCharsetException uce) {
				// In case P4Java's Perforce extended charsets are not
				// loaded in the VM's bootstrap classpath (i.e. P4Java JAR
				// file is inside a WAR deployed in a web app container like
				// Jetty, Tomcat, etc.), we'll instantiate it and lookup the
				// Perforce extended charsets.
				PerforceCharsetProvider p4CharsetProvider = new PerforceCharsetProvider();
				this.charset = p4CharsetProvider.charsetForName(javaCharsetName);
				this.clientBOM = false;

				// Throw the unsupported charset exception that was catched.
				if (isNull(this.charset)) {
					throw uce;
				}
			} catch (IllegalCharsetNameException icne) {
				// Throw a unsupported charset exception wrapped around
				// the illegal charset name exception.
				throw new UnsupportedCharsetException(icne.getLocalizedMessage());
			}
			// Set the new charset name
			this.charsetName = charsetName;
		}
	} else { // Reset the charset to "no charset"
		this.charsetName = null;
		this.charset = null;
		this.clientBOM = false;
	}
}