Example usage for org.apache.commons.io Charsets UTF_8

List of usage examples for org.apache.commons.io Charsets UTF_8

Introduction

In this page you can find the example usage for org.apache.commons.io Charsets UTF_8.

Prototype

Charset UTF_8

To view the source code for org.apache.commons.io Charsets UTF_8.

Click Source Link

Document

Eight-bit Unicode Transformation Format.

Usage

From source file:ro.ieugen.fileserver.http.HttpStaticFileServerHandler.java

private HttpResponse directoryListingResponse(File file) {
    final HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK);
    String directoryListing = directoryRenderer.renderDirectory(file);
    ChannelBuffer buffer = ChannelBuffers.dynamicBuffer();
    buffer.writeBytes(directoryListing.getBytes(Charsets.UTF_8));
    response.setContent(buffer);/*w w w .j a  v  a  2  s  .  com*/
    setContentLength(response, buffer.readableBytes());
    response.setHeader("Content-type", "text/html");
    return response;
}

From source file:uk.ac.ucl.excites.sapelli.shared.util.StringUtils.java

/**
 * Returns the number bytes a given string takes up when encoded as UTF-8 
 * /* www  . j  a va2 s .c  o m*/
 * @param string
 * @return number of bytes that would be used to write the string
 */
static public int sizeBytes(String string) {
    return sizeBytes(string, Charsets.UTF_8);
}

From source file:uk.ac.ucl.excites.sapelli.storage.eximport.csv.CSVRecordsExporter.java

@Override
protected void openWriter(String description, DateTime timestamp) throws IOException, FileStorageException {
    if (!FileHelpers.createDirectory(exportFolder))
        throw new FileStorageException(
                "Export folder (" + exportFolder + ") does not exist and could not be created!");
    writer = new FileWriter(
            exportFolder + File.separator
                    + FileHelpers.makeValidFileName("Records_" + description + "_"
                            + TimeUtils.getTimestampForFileName(timestamp) + "." + FILE_EXTENSION),
            Charsets.UTF_8);
    writer.open(FileHelpers.FILE_EXISTS_STRATEGY_REPLACE, FileHelpers.FILE_DOES_NOT_EXIST_STRATEGY_CREATE);
}

From source file:uk.ac.ucl.excites.sapelli.storage.eximport.xml.XMLRecordsExporter.java

@Override
protected void openWriter(String description, DateTime timestamp) throws IOException, FileStorageException {
    if (!FileHelpers.createDirectory(exportFolder))
        throw new FileStorageException(
                "Export folder (" + exportFolder + ") does not exist and could not be created!");
    writer = new FileWriter(
            exportFolder + File.separator
                    + FileHelpers.makeValidFileName("Records_"
                            + (description != null && !description.isEmpty() ? description + "_" : "")
                            + TimeUtils.getTimestampForFileName(timestamp) + "." + FILE_EXTENSION),
            Charsets.UTF_8);
    writer.open(FileHelpers.FILE_EXISTS_STRATEGY_REPLACE, FileHelpers.FILE_DOES_NOT_EXIST_STRATEGY_CREATE);
    writer.writeLine(XMLUtils.header(Charsets.UTF_8.name(), USES_XML_VERSION_11));
    writer.writeLine("<" + TAG_RECORDS_EXPORT + " " + ATTRIBUTE_EXPORTED_AT + "=\""
            + ExportedAtFormatter.print(timestamp) + "\">");
}

From source file:uk.ac.ucl.excites.sapelli.storage.model.columns.StringColumn.java

/**
 * For upgrade purposes only.//from  w  ww . j  ava  2s  . c om
 * 
 * @param stringColumn
 * @see uk.ac.ucl.excites.sapelli.storage.db.sql.upgrades.Beta17UpgradeStep
 * @return
 */
public static StringColumn Get3BytesPerCharUTF8Version(StringColumn stringColumn) {
    if (stringColumn == null || !Charsets.UTF_8.equals(stringColumn.getCharset()))
        return stringColumn;
    // else:
    return new StringColumn(stringColumn.name, stringColumn.optional, stringColumn.getMaximumChars() * 3,
            Charsets.UTF_8, stringColumn.defaultValue);
}

From source file:uk.ac.ucl.excites.sapelli.transmission.db.TransmissionStore.java

static private byte[] StringToBytes(String str) {
    return str.getBytes(Charsets.UTF_8);
}

From source file:uk.ac.ucl.excites.sapelli.transmission.db.TransmissionStore.java

static private String BytesToString(byte[] bytes) {
    return new String(bytes, Charsets.UTF_8);
}

From source file:uk.co.thinkofdeath.thinkcraft.bukkit.web.ChunkEndPoint.java

@Override
public void handle(ChannelHandlerContext context, URI uri, FullHttpRequest request) {
    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, context.alloc().buffer());
    response.headers().add("Access-Control-Allow-Origin", "*");
    response.headers().add("Access-Control-Allow-Methods", "POST");
    if (request.getMethod() == OPTIONS) {
        response.headers().add("Access-Control-Allow-Headers", "origin, content-type, accept");
    }//from   w w w.j a v  a  2  s .c o m

    if (request.getMethod() == POST) {
        String[] args = request.content().toString(Charsets.UTF_8).split(":");
        ByteBuf out = response.content();
        if (plugin.getChunkManager(plugin.getTargetWorld()).getChunkBytes(Integer.parseInt(args[0]),
                Integer.parseInt(args[1]), out)) {
            response.headers().add("Content-Encoding", "gzip");
        } else {
            out.writeBytes(new byte[1]);
        }
    }
    sendHttpResponse(context, request, response);
}

From source file:uk.co.thinkofdeath.thinkcraft.bukkit.web.InternalWebServer.java

@Override
public void handle(ChannelHandlerContext context, URI uri, FullHttpRequest request) throws Exception {
    if (request.getMethod() != HttpMethod.GET) {
        sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, METHOD_NOT_ALLOWED));
        return;/*from  www . j  a v a  2  s.com*/
    }
    String modified = request.headers().get(IF_MODIFIED_SINCE);
    if (modified != null && !modified.isEmpty()) {
        Date modifiedDate = format.parse(modified);

        if (modifiedDate.equals(plugin.getStartUpDate())) {
            sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, NOT_MODIFIED));
            return;
        }
    }

    String path = uri.getPath();
    if (path.equals("/")) {
        path = "/index.html";
    }

    ByteBuf buffer;
    try (InputStream stream = this.getClass().getClassLoader().getResourceAsStream("www" + path)) {
        if (stream == null) {
            sendHttpResponse(context, request, new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND));
            return;
        }
        ByteBufOutputStream out = new ByteBufOutputStream(context.alloc().buffer());
        IOUtils.copy(stream, out);
        buffer = out.buffer();
        out.close();
    }

    if (path.equals("/index.html")) {
        String page = buffer.toString(Charsets.UTF_8);
        page = page.replaceAll("%SERVERPORT%", Integer.toString(plugin.getConfiguration().getPort()));
        buffer.release();
        buffer = Unpooled.wrappedBuffer(page.getBytes(Charsets.UTF_8));
    }

    FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, buffer);

    response.headers().set(DATE, format.format(new Date()));
    response.headers().set(LAST_MODIFIED, format.format(plugin.getStartUpDate()));

    String ext = path.substring(path.lastIndexOf('.') + 1);
    String type = mimeTypes.containsKey(ext) ? mimeTypes.get(ext) : "text/plain";
    if (type.startsWith("text/")) {
        type += "; charset=UTF-8";
    }
    response.headers().set(CONTENT_TYPE, type);
    sendHttpResponse(context, request, response);
}

From source file:won.bot.framework.eventbot.action.impl.monitor.MessageLifecycleMonitoringAction.java

private void record(final Dataset dataset, final int[] counter) {

    counter[0]++;/* w  w w. j a v a 2  s .c om*/
    counter[1] = counter[1] + RdfUtils.getModelNames(dataset).size();
    Iterator<Quad> quadsIterator = dataset.asDatasetGraph().find();
    while (quadsIterator.hasNext()) {
        quadsIterator.next();
        counter[2]++;
    }
    counter[3] = counter[3] + RdfUtils.writeDatasetToString(dataset, Lang.TRIG).getBytes(Charsets.UTF_8).length;
}