List of usage examples for java.nio.charset Charset canEncode
public boolean canEncode()
From source file:Main.java
public static void main(String[] args) { Map<String, Charset> charsets = Charset.availableCharsets(); Iterator<Charset> iterator = charsets.values().iterator(); while (iterator.hasNext()) { Charset cs = (Charset) iterator.next(); System.out.println(cs.displayName()); System.out.println(cs.canEncode()); }/* w w w. j a v a 2 s. co m*/ }
From source file:org.sonews.daemon.sync.SynchronousNNTPConnection.java
/** * Encodes the given CharBuffer using the given Charset to a bunch of * ByteBuffers (each 512 bytes large) and enqueues them for writing at the * connected SocketChannel.// ww w . j av a2 s . c o m * * @throws java.io.IOException */ private void writeToChannel(CharBuffer characters, final Charset charset, CharSequence debugLine) throws IOException { if (!charset.canEncode()) { Log.get().log(Level.SEVERE, "FATAL: Charset {0} cannot encode!", charset); return; } // Write characters to output buffers LineEncoder lenc = new LineEncoder(characters, charset); lenc.encode(lineBuffers); enableWriteEvents(debugLine); }
From source file:com.sonicle.webtop.core.Service.java
public void processLookupTextEncodings(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {/* w ww . ja v a 2s . co m*/ ArrayList<JsSimple> items = new ArrayList<>(); try { SortedMap<String, Charset> charsets = Charset.availableCharsets(); for (Charset charset : charsets.values()) { if (!charset.canEncode()) continue; items.add(new JsSimple(charset.name(), charset.displayName(Locale.ENGLISH))); } new JsonResult("encodings", items, items.size()).printTo(out); } catch (Exception ex) { logger.error("Error in LookupTextEncodings", ex); new JsonResult(false, "Unable to lookup available text encodings").printTo(out); } }