use of java.nio.charset.UnsupportedCharsetException in project lombok by rzwitserloot.
the class Delombok method main.
public static void main(String[] rawArgs) {
CmdReader<CmdArgs> reader = CmdReader.of(CmdArgs.class);
CmdArgs args;
try {
args = reader.make(rawArgs);
} catch (InvalidCommandLineException e) {
System.err.println("ERROR: " + e.getMessage());
System.err.println(reader.generateCommandLineHelp("delombok"));
System.exit(1);
return;
}
if (args.help || (args.input.isEmpty() && !args.formatHelp)) {
if (!args.help)
System.err.println("ERROR: no files or directories to delombok specified.");
System.err.println(reader.generateCommandLineHelp("delombok"));
System.exit(args.help ? 0 : 1);
return;
}
Delombok delombok = new Delombok();
if (args.quiet)
delombok.setFeedback(new PrintStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
//dummy - do nothing.
}
}));
if (args.formatHelp) {
System.out.println("Available format keys (to use, -f key:value -f key2:value2 -f ... ):");
for (Map.Entry<String, String> e : FormatPreferences.getKeysAndDescriptions().entrySet()) {
System.out.print(" ");
System.out.print(e.getKey());
System.out.println(":");
System.out.println(indentAndWordbreak(e.getValue(), 4, 70));
}
System.out.println("Example: -f indent:4 -f emptyLines:indent");
System.out.println("The '-f pretty' option is shorthand for '-f suppressWarnings:skip -f generated:skip -f danceAroundIdeChecks:skip -f generateDelombokComment:skip -f javaLangAsFQN:skip'");
System.exit(0);
return;
}
try {
delombok.setFormatPreferences(formatOptionsToMap(args.format));
} catch (InvalidFormatOptionException e) {
System.out.println(e.getMessage() + " Try --format-help.");
System.exit(1);
return;
}
if (args.encoding != null) {
try {
delombok.setCharset(args.encoding);
} catch (UnsupportedCharsetException e) {
System.err.println("ERROR: Not a known charset: " + args.encoding);
System.exit(1);
return;
}
}
if (args.verbose)
delombok.setVerbose(true);
if (args.nocopy)
delombok.setNoCopy(true);
if (args.print) {
delombok.setOutputToStandardOut();
} else {
delombok.setOutput(new File(args.target));
}
if (args.classpath != null)
delombok.setClasspath(args.classpath);
if (args.sourcepath != null)
delombok.setSourcepath(args.sourcepath);
if (args.bootclasspath != null)
delombok.setBootclasspath(args.bootclasspath);
try {
for (String in : args.input) {
File f = new File(in).getAbsoluteFile();
if (f.isFile()) {
delombok.addFile(f.getParentFile(), f.getName());
} else if (f.isDirectory()) {
delombok.addDirectory(f);
} else if (!f.exists()) {
if (!args.quiet)
System.err.println("WARNING: does not exist - skipping: " + f);
} else {
if (!args.quiet)
System.err.println("WARNING: not a standard file or directory - skipping: " + f);
}
}
delombok.delombok();
} catch (Exception e) {
if (!args.quiet) {
String msg = e.getMessage();
if (msg != null && msg.startsWith("DELOMBOK: "))
System.err.println(msg.substring("DELOMBOK: ".length()));
else {
e.printStackTrace();
}
System.exit(1);
return;
}
}
}
use of java.nio.charset.UnsupportedCharsetException in project lombok by rzwitserloot.
the class DelombokTaskImpl method execute.
public void execute(Location location) throws BuildException {
if (fromDir == null && path == null)
throw new BuildException("Either 'from' attribute, or nested <fileset> tags are required.");
if (fromDir != null && path != null)
throw new BuildException("You can't specify both 'from' attribute and nested filesets. You need one or the other.");
if (toDir == null)
throw new BuildException("The to attribute is required.");
Delombok delombok = new Delombok();
if (verbose)
delombok.setVerbose(true);
try {
if (encoding != null)
delombok.setCharset(encoding);
} catch (UnsupportedCharsetException e) {
throw new BuildException("Unknown charset: " + encoding, location);
}
if (classpath != null)
delombok.setClasspath(classpath.toString());
if (sourcepath != null)
delombok.setSourcepath(sourcepath.toString());
try {
delombok.setFormatPreferences(Delombok.formatOptionsToMap(formatOptions));
} catch (InvalidFormatOptionException e) {
throw new BuildException(e.getMessage() + " Run java -jar lombok.jar --format-help for detailed format help.");
}
delombok.setOutput(toDir);
try {
if (fromDir != null)
delombok.addDirectory(fromDir);
else {
Iterator<?> it = path.iterator();
while (it.hasNext()) {
FileResource fileResource = (FileResource) it.next();
File baseDir = fileResource.getBaseDir();
if (baseDir == null) {
File file = fileResource.getFile();
delombok.addFile(file.getParentFile(), file.getName());
} else {
delombok.addFile(baseDir, fileResource.getName());
}
}
}
delombok.delombok();
} catch (IOException e) {
throw new BuildException("I/O problem during delombok", e, location);
}
}
use of java.nio.charset.UnsupportedCharsetException in project undertow by undertow-io.
the class HttpServletRequestImpl method getReader.
@Override
public BufferedReader getReader() throws IOException {
if (reader == null) {
if (servletInputStream != null) {
throw UndertowServletMessages.MESSAGES.getInputStreamAlreadyCalled();
}
Charset charSet = servletContext.getDeployment().getDefaultCharset();
if (characterEncoding != null) {
charSet = characterEncoding;
} else {
String c = getCharacterEncodingFromHeader();
if (c != null) {
try {
charSet = Charset.forName(c);
} catch (UnsupportedCharsetException e) {
throw new UnsupportedEncodingException();
}
}
}
reader = new BufferedReader(new InputStreamReader(exchange.getInputStream(), charSet));
}
readStarted = true;
return reader;
}
use of java.nio.charset.UnsupportedCharsetException in project intellij-community by JetBrains.
the class JdkUtil method appendEncoding.
private static void appendEncoding(SimpleJavaParameters javaParameters, GeneralCommandLine commandLine, ParametersList parametersList) {
// Value of file.encoding and charset of GeneralCommandLine should be in sync in order process's input and output be correctly handled.
String encoding = parametersList.getPropertyValue("file.encoding");
if (encoding == null) {
Charset charset = javaParameters.getCharset();
if (charset == null)
charset = EncodingManager.getInstance().getDefaultCharset();
commandLine.addParameter("-Dfile.encoding=" + charset.name());
commandLine.withCharset(charset);
} else {
try {
Charset charset = Charset.forName(encoding);
commandLine.withCharset(charset);
} catch (UnsupportedCharsetException | IllegalCharsetNameException ignore) {
}
}
}
use of java.nio.charset.UnsupportedCharsetException in project XobotOS by xamarin.
the class Properties method storeToXML.
/**
* Writes all properties stored in this instance into the {@code
* OutputStream} in XML representation. The DOCTYPE is
*
* <pre>
* <!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
* </pre>
*
* If the comment is null, no comment is added to the output. The parameter
* {@code encoding} defines which encoding should be used. The {@code
* OutputStream} is not closed at the end.
*
* @param os the {@code OutputStream} to write to.
* @param comment the comment to add. If null, no comment is added.
* @param encoding the code identifying the encoding that should be used to
* write into the {@code OutputStream}.
* @throws IOException if an error occurs during writing to the output.
*/
public synchronized void storeToXML(OutputStream os, String comment, String encoding) throws IOException {
if (os == null || encoding == null) {
throw new NullPointerException();
}
/*
* We can write to XML file using encoding parameter but note that some
* aliases for encodings are not supported by the XML parser. Thus we
* have to know canonical name for encoding used to store data in XML
* since the XML parser must recognize encoding name used to store data.
*/
String encodingCanonicalName;
try {
encodingCanonicalName = Charset.forName(encoding).name();
} catch (IllegalCharsetNameException e) {
System.out.println("Warning: encoding name " + encoding + " is illegal, using UTF-8 as default encoding");
encodingCanonicalName = "UTF-8";
} catch (UnsupportedCharsetException e) {
System.out.println("Warning: encoding " + encoding + " is not supported, using UTF-8 as default encoding");
encodingCanonicalName = "UTF-8";
}
PrintStream printStream = new PrintStream(os, false, encodingCanonicalName);
printStream.print("<?xml version=\"1.0\" encoding=\"");
printStream.print(encodingCanonicalName);
printStream.println("\"?>");
printStream.print("<!DOCTYPE properties SYSTEM \"");
printStream.print(PROP_DTD_NAME);
printStream.println("\">");
printStream.println("<properties>");
if (comment != null) {
printStream.print("<comment>");
printStream.print(substitutePredefinedEntries(comment));
printStream.println("</comment>");
}
for (Map.Entry<Object, Object> entry : entrySet()) {
String keyValue = (String) entry.getKey();
String entryValue = (String) entry.getValue();
printStream.print("<entry key=\"");
printStream.print(substitutePredefinedEntries(keyValue));
printStream.print("\">");
printStream.print(substitutePredefinedEntries(entryValue));
printStream.println("</entry>");
}
printStream.println("</properties>");
printStream.flush();
}
Aggregations