Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
// (c) 2012 B Smith-Mannschott -- Distributed under the Eclipse Public License
package us.bpsm.edn.printer;
import java.io.IOException;
import java.io.Writer;
import java.io.Closeable;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Timestamp;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.Map;
import java.util.RandomAccess;
import java.util.Set;
import java.util.UUID;
import us.bpsm.edn.EdnException;
import us.bpsm.edn.EdnIOException;
import us.bpsm.edn.Keyword;
import us.bpsm.edn.Symbol;
import us.bpsm.edn.Tag;
import us.bpsm.edn.TaggedValue;
import us.bpsm.edn.parser.InstantUtils;
import us.bpsm.edn.parser.Parser;
import us.bpsm.edn.protocols.Protocol;
import us.bpsm.edn.protocols.Protocols;
import us.bpsm.edn.util.CharClassify;
/**
* Factory for creating {@link Printer}s and related Objects.
*/
public class Printers {
private Printers() {
throw new UnsupportedOperationException();
}
/**
* Return a new Printer with the default printing
* protocol. Everything the printer prints will be appended to
* {@code out}. {@link Printer#close()} will close {@code
* out}, provided {@code out} implements {@link Closeable}.
*
* @param out to which values will be printed. Never null.
*
* @return a Printer with default configuration, never null.
*/
public static Printer newPrinter(final Appendable out) {
return newPrinter(defaultPrinterProtocol(), out);
}
/**
* Print {@code ednValue} to a new String using the default
* printing protocol.
*
* @param ednValue the value to be returned as a String in edn syntax.
*
* @return A string in edn syntax. Not null, not empty.
*/
public static String printString(Object ednValue) {
return printString(defaultPrinterProtocol(), ednValue);
}
/**
* Print {@code ednValue} to a new String using the printing
* protocol given as {@code fns}.
*
* @param fns a Protocol which knows how to print all the classes
* of objects that we'll be asking our Printer to print.
* Never null. Never null.
*
* @param ednValue the value to be returned as a String in edn syntax.
*
* @return A string in edn syntax. Not null, not empty.
*/
public static String printString(final Protocol> fns,
Object ednValue) {
StringBuilder sb = new StringBuilder();
newPrinter(fns, sb).printValue(ednValue);
return sb.toString();
}
/**
* Return a new Printer with the printing protocol given as {@code
* fns}. Everything the printer prints will be appended to {@code
* writer}. {@link Printer#close()} will close {@code out}, if
* {@code out} implements {@link Closeable}.
*
* @param fns a Protocol which knows how to print all the classes
* of objects that we'll be asking our Printer to print.
* Never null. Never null.
* @param out to which values will be printed. Never null.
*
* @return a Printer, never null.
*/
public static Printer newPrinter(final Protocol> fns,
final Appendable out) {
return new Printer() {
int softspace = 0;
public void close() {
if (out instanceof Closeable) {
try {
((Closeable)out).close();
} catch (IOException e) {
throw new EdnIOException(e);
}
}
}
public Printer append(CharSequence csq) {
try {
if (softspace > 1 && csq.length() > 0 &&
!CharClassify.isWhitespace(csq.charAt(0))) {
out.append(' ');
}
softspace = 0;
out.append(csq);
return this;
} catch (IOException e) {
throw new EdnIOException(e);
}
}
public Printer append(char c) {
try {
if (softspace > 1 && !CharClassify.isWhitespace(c)) {
out.append(' ');
}
softspace = 0;
out.append(c);
return this;
} catch (IOException e) {
throw new EdnIOException(e);
}
}
public Printer printValue(Object ednValue) {
@SuppressWarnings("unchecked")
Printer.Fn