private static void checkCharsetName(String name) { if (name.isEmpty()) { throw new IllegalCharsetNameException(name); } if (!isValidCharsetNameStart(name.charAt(0))) { throw new IllegalCharsetNameException(name); } for (int i = 1; i < name.length(); ++i) { if (!isValidCharsetNamePart(name.charAt(i))) { throw new IllegalCharsetNameException(name); } } }
/** * Creates bulk load CSV parser. * * @param format Format options (parsed from COPY command). */ public BulkLoadCsvParser(BulkLoadCsvFormat format) { try { Charset charset = format.inputCharsetName() == null ? BulkLoadFormat.DEFAULT_INPUT_CHARSET : Charset.forName(format.inputCharsetName()); inputBlock = new CharsetDecoderBlock(charset); } catch (IllegalCharsetNameException e) { throw new IgniteSQLException("Unknown charset name: '" + format.inputCharsetName() + "': " + e.getMessage()); } catch (UnsupportedCharsetException e) { throw new IgniteSQLException("Charset is not supported: '" + format.inputCharsetName() + "': " + e.getMessage()); } collectorBlock = new StrListAppenderBlock(); // Handling of the other options is to be implemented in IGNITE-7537. inputBlock.append(new LineSplitterBlock(format.lineSeparator())) .append(new CsvLineProcessorBlock(format.fieldSeparator(), format.quoteChars())) .append(collectorBlock); }
private static Charset getCharset(final Field field) { final Encoding annotation = field.getAnnotation(Encoding.class); try { return Charset.forName(annotation != null ? annotation.value() : "UTF-8"); //$NON-NLS-1$ } catch (final UnsupportedCharsetException exception) { logger.log(ILevel.ERROR, exception.getLocalizedMessage(), exception); return Charset.forName("UTF-8"); //$NON-NLS-1$ } catch (final IllegalCharsetNameException exception) { logger.log(ILevel.ERROR, exception.getLocalizedMessage(), exception); return Charset.forName("UTF-8"); //$NON-NLS-1$ } catch (final IllegalArgumentException exception) { logger.log(ILevel.ERROR, exception.getLocalizedMessage(), exception); return Charset.forName("UTF-8"); //$NON-NLS-1$ } } }
public static CharacterEncoding fromString(final String name) { requireNonNull(name,"Character encoding name cannot be null"); try { if(WILDCARD.equals(name)) { return wildcard(); } else { return of(Charset.forName(name)); } } catch (final UnsupportedCharsetException ex) { throw new IllegalArgumentException("Unsupported character encoding '"+ex.getCharsetName()+"'",ex); } catch (final IllegalCharsetNameException ex) { throw new IllegalArgumentException("Invalid character encoding name '"+ex.getCharsetName()+"'",ex); } }
private static Charset getCharset(final Field field) { final Encoding annotation = field.getAnnotation(Encoding.class); try { return Charset.forName(annotation != null ? annotation.value() : "UTF-8"); //$NON-NLS-1$ } catch (final UnsupportedCharsetException exception) { logger.log(ILevel.ERROR, exception.getLocalizedMessage(), exception); return Charset.forName("UTF-8"); //$NON-NLS-1$ } catch (final IllegalCharsetNameException exception) { logger.log(ILevel.ERROR, exception.getLocalizedMessage(), exception); return Charset.forName("UTF-8"); //$NON-NLS-1$ } catch (final IllegalArgumentException exception) { logger.log(ILevel.ERROR, exception.getLocalizedMessage(), exception); return Charset.forName("UTF-8"); //$NON-NLS-1$ } } }
private static void checkParameter(final String parameter, String value) { checkHasLength(parameter, "Parameter name cannot be empty"); checkToken(parameter,"Invalid parameter name '%s'",parameter); checkHasLength(value, "Value for parameter '%s' cannot be empty",parameter); if(MediaTypes.PARAM_CHARSET.equalsIgnoreCase(parameter)) { final String unquotedValue = HttpUtils.unquote(value); try { Charset.forName(unquotedValue); } catch (final UnsupportedCharsetException ex) { throw new IllegalArgumentException("Unsupported charset '"+ex.getCharsetName()+"'",ex); } catch (final IllegalCharsetNameException ex) { throw new IllegalArgumentException("Invalid charset name '"+ex.getCharsetName()+"'",ex); } } else if(!HttpUtils.isQuotedString(value)) { checkToken(value); } else { checkQuotedString(HttpUtils.unquote(value)); } }
public Connection.Request postDataCharset(String charset) { Validate.notNull(charset, "Charset must not be null"); if (!Charset.isSupported(charset)) throw new IllegalCharsetNameException(charset); this.postDataCharset = charset; return this; }
/** * Gets the charset belonging to the given {@code encoding}. * @param encoding The encoding - if {@code null} then the default platform * encoding is used. * @return The charset belonging to the given {@code encoding} or the platform default. * Never {@code null}. */ private static Charset getCharset(String encoding) { Charset charset = null; if (encoding != null) { try { charset = Charset.forName(encoding); } catch(IllegalCharsetNameException e) { LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})", new Object[]{encoding, e.getMessage()}); } catch(UnsupportedCharsetException e) { LOG.log(Level.WARNING, "JNA Warning: Encoding ''{0}'' is unsupported ({1})", new Object[]{encoding, e.getMessage()}); } } if (charset == null) { LOG.log(Level.WARNING, "JNA Warning: Using fallback encoding {0}", Native.DEFAULT_CHARSET); charset = Native.DEFAULT_CHARSET; } return charset; }
throw new UnsupportedCharsetException(icne.getLocalizedMessage());
@Test public void cannotParseMediaTypesWithBadCharsetName() throws Exception { try { createParam("charset=<catepora>"); fail("Should fail for bad-name charsets"); } catch (final InvalidMediaTypeException e) { assertThat(e.getCause(),instanceOf(IllegalArgumentException.class)); assertThat(((IllegalCharsetNameException)e.getCause().getCause()).getCharsetName(),equalTo("<catepora>")); } }
private void setEncoding(String name) { EncodingDB.Entry e = EncodingDB.getEncodings().get(Bytes.toBytes(name)); if (e != null) { encoding = e.getEncoding(); } else { throw new IllegalCharsetNameException(name); } } }
public String validate(String newValueCandidate) { try { Charset.forName(newValueCandidate); return ""; } catch (IllegalCharsetNameException e) { return "Illegal charset: " + e.getMessage(); } catch (UnsupportedCharsetException e) { return "Unsupported charset: " + e.getMessage(); } }
throw new UnsupportedCharsetException(icne.getLocalizedMessage());
throw new IllegalCharsetNameException(null);
@Override public String validate(String newValueCandidate) { try { Charset.forName(newValueCandidate); return ""; } catch (IllegalCharsetNameException e) { return "Illegal charset: " + e.getMessage(); } catch (UnsupportedCharsetException e) { return "Unsupported charset: " + e.getMessage(); } }
throw new IllegalCharsetNameException(name); return charset; } else if ("none".equals(lower) || "no".equals(lower)) { throw new IllegalCharsetNameException(name); } else { Matcher iso = ISO_NAME_PATTERN.matcher(lower);
@Override public String validate(String newValueCandidate) { try { Charset.forName(newValueCandidate); return ""; } catch (IllegalCharsetNameException e) { return "Illegal charset: " + e.getMessage(); } catch (UnsupportedCharsetException e) { return "Unsupported charset: " + e.getMessage(); } }
private void setEncoding(String name) { EncodingDB.Entry e = EncodingDB.getEncodings().get(Bytes.toBytes(name)); if (e != null) { encoding = e.getEncoding(); } else { throw new IllegalCharsetNameException(name); } } }
public Charset getEncoding(FileObject file) { assert file != null; assert file.equals(getPrimaryFile()); String charsetName = getFileEncoding(); try { return Charset.forName(charsetName); } catch (IllegalCharsetNameException ichse) { //the jsp templates contains the ${encoding} property //so the ICHNE is always thrown for them, just ignore Boolean template = (Boolean)file.getAttribute("template");//NOI18N if(template == null || !template.booleanValue()) { Logger.getLogger("global").log(Level.INFO, "Detected illegal charset name in file " + file.getNameExt() + " (" + ichse.getMessage() + ")"); //NOI18N } } catch (UnsupportedCharsetException uchse) { Logger.getLogger("global").log(Level.INFO, "Detected unsupported charset name in file " + file.getNameExt() + " (" + uchse.getMessage() + ")"); //NOI18N } return null; }
/** * * @param icuCanonicalName * @param canonicalName * @param aliases * @stable ICU 3.6 */ protected CharsetICU(String icuCanonicalName, String canonicalName, String[] aliases) { super(canonicalName,aliases); if(canonicalName.length() == 0){ throw new IllegalCharsetNameException(canonicalName); } this.icuCanonicalName = icuCanonicalName; }