/** * Returns the NIO charset matching the character set name. * * @return The NIO charset. */ public java.nio.charset.Charset toCharset() { return java.nio.charset.Charset.forName(getName()); } }
/** * Returns the NIO charset matching the character set name. * * @return The NIO charset. */ public java.nio.charset.Charset toCharset() { return java.nio.charset.Charset.forName(getName()); } }
/** * Returns a reader from an input stream and a character set. * * @param stream * The input stream. * @param characterSet * The character set. May be null. * @return The equivalent reader. * @throws UnsupportedEncodingException * if a character set is given, but not supported */ public static Reader getReader(InputStream stream, CharacterSet characterSet) throws UnsupportedEncodingException { if (characterSet != null) { return new InputStreamReader(stream, characterSet.getName()); } return new InputStreamReader(stream); }
/** * Returns a reader from an input stream and a character set. * * @param stream * The input stream. * @param characterSet * The character set. May be null. * @return The equivalent reader. * @throws UnsupportedEncodingException * if a character set is given, but not supported */ public static Reader getReader(InputStream stream, CharacterSet characterSet) throws UnsupportedEncodingException { if (characterSet != null) { return new InputStreamReader(stream, characterSet.getName()); } return new InputStreamReader(stream); }
@Override public void write(OutputStream outputStream) throws IOException { Writer writer = null; if (getCharacterSet() != null) { writer = new OutputStreamWriter(outputStream, getCharacterSet() .getName()); } else { writer = new OutputStreamWriter(outputStream); } write(writer); writer.flush(); }
@Override public InputStream getStream() throws IOException { CharacterSet charset = getCharacterSet() == null ? CharacterSet.ISO_8859_1 : getCharacterSet(); ByteArrayInputStream result = new ByteArrayInputStream(getText() .getBytes(charset.getName())); return result; }
@Override public InputStream getStream() throws IOException { CharacterSet charset = getCharacterSet() == null ? CharacterSet.ISO_8859_1 : getCharacterSet(); ByteArrayInputStream result = new ByteArrayInputStream(getText() .getBytes(charset.getName())); return result; }
@Override protected void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException { JTMTopicMapWriter writer = new JTMTopicMapWriter(outputStream, characterSet.getName()); writer.write((TMObjectIF) source); } }
@Override protected void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException { new LTMTopicMapWriter(outputStream, characterSet.getName()).write((TopicMapIF) source); } }
@Override public void write(OutputStream outputStream) throws IOException { if (getText() != null) { OutputStreamWriter osw = null; if (getCharacterSet() != null) { osw = new OutputStreamWriter(outputStream, getCharacterSet() .getName()); } else { osw = new OutputStreamWriter(outputStream); } osw.write(getText()); osw.flush(); } }
@Override public InputStream getStream() throws IOException { if (getText() != null) { if (getCharacterSet() != null) { return new ByteArrayInputStream(getText().getBytes( getCharacterSet().getName())); } return new ByteArrayInputStream(getText().getBytes()); } return null; }
/** * Converts the representation to a string value. Be careful when using this * method as the conversion of large content to a string fully stored in * memory can result in OutOfMemoryErrors being thrown. * * @return The representation as a string value. */ public String getText() throws IOException { String result = null; if (isAvailable()) { final ByteArrayOutputStream baos = new ByteArrayOutputStream(); write(baos); if (getCharacterSet() != null) { result = baos.toString(getCharacterSet().getName()); } else { result = baos.toString(); } } return result; }
/** * Writes the HTTP "Content-Type" header. * * @param mediaType * The representation media type. * @param characterSet * The representation character set. * @return The HTTP "Content-Type" header. */ public static String writeHeader(MediaType mediaType, CharacterSet characterSet) { String result = mediaType.toString(); // Specify the character set parameter if required if ((mediaType.getParameters().getFirstValue("charset") == null) && (characterSet != null)) { result = result + "; charset=" + characterSet.getName(); } return result; }
@Override protected void writeFragment(OutputStream outputStream, Object source, CharacterSet characterSet) throws IOException { if (source instanceof TopicMapIF) { XTMTopicMapWriter writer = new XTMTopicMapWriter(outputStream, characterSet.getName()); writer.setVersion(XTMVersion.XTM_2_1); // todo: config writer.write((TopicMapIF) source); } if (source instanceof TopicIF) { XTMTopicMapFragmentWriter writer = new XTMTopicMapFragmentWriter(outputStream, characterSet.getName()); writer.startTopicMap(); writer.exportTopic((TopicIF) source); writer.endTopicMap(); } // todo: can source be any other class here? } }