/** * Defines the default <code>Charset</code> used in case the buffer represents * an 8-bit <code>Charset</code>. * * @param defaultCharset the default <code>Charset</code> to be returned * if an 8-bit <code>Charset</code> is encountered. */ public void setDefaultCharset(Charset defaultCharset) { if (defaultCharset != null) this.defaultCharset = defaultCharset; else this.defaultCharset = getDefaultSystemCharset(); }
/** * @param infile the file to create a GroovyCodeSource for. * @throws IOException if an issue arises opening and reading the file. */ public GroovyCodeSource(final File infile) throws IOException { this(infile, CharsetToolkit.getDefaultSystemCharset().name()); }
/** * Read the content of this URL and returns it as a String. * * @param url URL to read content from * @return the text from that URL * @throws IOException if an IOException occurs. * @since 1.0 */ public static String getText(URL url) throws IOException { return getText(url, CharsetToolkit.getDefaultSystemCharset().name()); }
private void initSourceEncoding(CompilerConfiguration config) { sourceEncoding = config.getSourceEncoding(); if (null == sourceEncoding) { // Keep the same default source encoding with the one used by #parseClass(InputStream, String) // TODO should we use org.codehaus.groovy.control.CompilerConfiguration.DEFAULT_SOURCE_ENCODING instead? sourceEncoding = CharsetToolkit.getDefaultSystemCharset().name(); } }
/** * Constructor of the <code>CharsetToolkit</code> utility class. * * @param file of which we want to know the encoding. */ public CharsetToolkit(File file) throws IOException { this.file = file; this.defaultCharset = getDefaultSystemCharset(); this.charset = null; try (InputStream input = new FileInputStream(file)) { byte[] bytes = new byte[4096]; int bytesRead = input.read(bytes); if (bytesRead == -1) { this.buffer = EMPTY_BYTE_ARRAY; } else if (bytesRead < 4096) { byte[] bytesToGuess = new byte[bytesRead]; System.arraycopy(bytes, 0, bytesToGuess, 0, bytesRead); this.buffer = bytesToGuess; } else { this.buffer = bytes; } } }
/** * Read the content of this URL and returns it as a String. * The default connection parameters can be modified by adding keys to the * <i>parameters map</i>: * <ul> * <li>connectTimeout : the connection timeout</li> * <li>readTimeout : the read timeout</li> * <li>useCaches : set the use cache property for the URL connection</li> * <li>allowUserInteraction : set the user interaction flag for the URL connection</li> * <li>requestProperties : a map of properties to be passed to the URL connection</li> * </ul> * * @param url URL to read content from * @param parameters connection parameters * @return the text from that URL * @throws IOException if an IOException occurs. * @since 1.8.1 */ public static String getText(URL url, Map parameters) throws IOException { return getText(url, parameters, CharsetToolkit.getDefaultSystemCharset().name()); }
/** * Defines the default <code>Charset</code> used in case the buffer represents * an 8-bit <code>Charset</code>. * * @param defaultCharset the default <code>Charset</code> to be returned * if an 8-bit <code>Charset</code> is encountered. */ public void setDefaultCharset(Charset defaultCharset) { if (defaultCharset != null) this.defaultCharset = defaultCharset; else this.defaultCharset = getDefaultSystemCharset(); }
/** * Defines the default <code>Charset</code> used in case the buffer represents * an 8-bit <code>Charset</code>. * * @param defaultCharset the default <code>Charset</code> to be returned by <code>guessEncoding()</code> * if an 8-bit <code>Charset</code> is encountered. */ public void setDefaultCharset(Charset defaultCharset) { if (defaultCharset != null) this.defaultCharset = defaultCharset; else this.defaultCharset = getDefaultSystemCharset(); }
/** * Defines the default <code>Charset</code> used in case the buffer represents * an 8-bit <code>Charset</code>. * * @param defaultCharset the default <code>Charset</code> to be returned by <code>guessEncoding()</code> * if an 8-bit <code>Charset</code> is encountered. */ public void setDefaultCharset(Charset defaultCharset) { if (defaultCharset != null) this.defaultCharset = defaultCharset; else this.defaultCharset = getDefaultSystemCharset(); }
/** * Defines the default <code>Charset</code> used in case the buffer represents * an 8-bit <code>Charset</code>. * * @param defaultCharset the default <code>Charset</code> to be returned by <code>guessEncoding()</code> * if an 8-bit <code>Charset</code> is encountered. */ public void setDefaultCharset(Charset defaultCharset) { if (defaultCharset != null) this.defaultCharset = defaultCharset; else this.defaultCharset = getDefaultSystemCharset(); }
/** * @param infile the file to create a GroovyCodeSource for. * @throws IOException if an issue arises opening and reading the file. */ public GroovyCodeSource(final File infile) throws IOException { this(infile, CharsetToolkit.getDefaultSystemCharset().name()); }
/** * Read the content of this URL and returns it as a String. * * @param url URL to read content from * @param parameters connection parameters * @return the text from that URL * @throws IOException if an IOException occurs. * @since 1.8.1 */ public static String getText(URL url, Map parameters) throws IOException { return getText(url, parameters, CharsetToolkit.getDefaultSystemCharset().toString()); }
/** * Read the content of this URL and returns it as a String. * * @param url URL to read content from * @return the text from that URL * @throws IOException if an IOException occurs. * @since 1.0 */ public static String getText(URL url) throws IOException { return getText(url, CharsetToolkit.getDefaultSystemCharset().toString()); }
/** * Read the content of this URL and returns it as a String. * * @param url URL to read content from * @return the text from that URL * @throws IOException if an IOException occurs. * @since 1.0 */ public static String getText(URL url) throws IOException { return getText(url, CharsetToolkit.getDefaultSystemCharset().toString()); }
/** * Read the content of this URL and returns it as a String. * * @param url URL to read content from * @return the text from that URL * @throws IOException if an IOException occurs. */ public static String getText(URL url) throws IOException { return getText(url, CharsetToolkit.getDefaultSystemCharset().toString()); }
/** * Read the content of this URL and returns it as a String. * * @param url URL to read content from * @return the text from that URL * @throws IOException if an IOException occurs. * @since 1.0 */ public static String getText(URL url) throws IOException { return getText(url, CharsetToolkit.getDefaultSystemCharset().toString()); }
/** * Constructor of the <code>CharsetToolkit</code> utility class. * * @param file of which we want to know the encoding. */ public CharsetToolkit(File file) throws IOException { this.file = file; this.defaultCharset = getDefaultSystemCharset(); this.charset = null; InputStream input = new FileInputStream(file); try { byte[] bytes = new byte[4096]; int bytesRead = input.read(bytes); if (bytesRead == -1) { this.buffer = EMPTY_BYTE_ARRAY; } else if (bytesRead < 4096) { byte[] bytesToGuess = new byte[bytesRead]; System.arraycopy(bytes, 0, bytesToGuess, 0, bytesRead); this.buffer = bytesToGuess; } else { this.buffer = bytes; } } finally { try {input.close();} catch (IOException e){ // IGNORE } } }
/** * Constructor of the <code>CharsetToolkit</code> utility class. * * @param file of which we want to know the encoding. */ public CharsetToolkit(File file) throws IOException { this.file = file; this.defaultCharset = getDefaultSystemCharset(); this.charset = null; InputStream input = new FileInputStream(file); try { byte[] bytes = new byte[4096]; int bytesRead = input.read(bytes); if (bytesRead == -1) { this.buffer = EMPTY_BYTE_ARRAY; } else if (bytesRead < 4096) { byte[] bytesToGuess = new byte[bytesRead]; System.arraycopy(bytes, 0, bytesToGuess, 0, bytesRead); this.buffer = bytesToGuess; } else { this.buffer = bytes; } } finally { try {input.close();} catch (IOException e){ // IGNORE } } }
/** * Constructor of the <code>CharsetToolkit</code> utility class. * * @param file of which we want to know the encoding. */ public CharsetToolkit(File file) throws IOException { this.file = file; this.defaultCharset = getDefaultSystemCharset(); this.charset = null; InputStream input = new FileInputStream(file); try { byte[] bytes = new byte[4096]; int bytesRead = input.read(bytes); if (bytesRead == -1) { this.buffer = EMPTY_BYTE_ARRAY; } else if (bytesRead < 4096) { byte[] bytesToGuess = new byte[bytesRead]; System.arraycopy(bytes, 0, bytesToGuess, 0, bytesRead); this.buffer = bytesToGuess; } else { this.buffer = bytes; } } finally { try {input.close();} catch (IOException e){ // IGNORE } } }
/** * Constructor of the <code>CharsetToolkit</code> utility class. * * @param file of which we want to know the encoding. */ public CharsetToolkit(File file) throws IOException { this.file = file; this.defaultCharset = getDefaultSystemCharset(); this.charset = null; InputStream input = new FileInputStream(file); try { byte[] bytes = new byte[4096]; int bytesRead = input.read(bytes); if (bytesRead == -1) { this.buffer = EMPTY_BYTE_ARRAY; } else if (bytesRead < 4096) { byte[] bytesToGuess = new byte[bytesRead]; System.arraycopy(bytes, 0, bytesToGuess, 0, bytesRead); this.buffer = bytesToGuess; } else { this.buffer = bytes; } } finally { try {input.close();} catch (IOException e){ // IGNORE } } }