List of usage examples for org.apache.commons.compress.utils Charsets UTF_8
Charset UTF_8
To view the source code for org.apache.commons.compress.utils Charsets UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:android.framework.org.apache.harmony.security_custom.asn1.ASN1UTCTime.java
@Override public void setEncodingContent(BerOutputStream out) { SimpleDateFormat sdf = new SimpleDateFormat(UTC_PATTERN); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); out.content = sdf.format(out.content).getBytes(Charsets.UTF_8); out.length = ((byte[]) out.content).length; }
From source file:android.framework.org.apache.harmony.security_custom.asn1.ASN1GeneralizedTime.java
public void setEncodingContent(BerOutputStream out) { SimpleDateFormat sdf = new SimpleDateFormat(GEN_PATTERN); sdf.setTimeZone(TimeZone.getTimeZone("UTC")); String temp = sdf.format(out.content); // cut off trailing 0s int nullId;/*www .j a v a 2 s .co m*/ int currLength; while (((nullId = temp.lastIndexOf('0', currLength = temp.length() - 1)) != -1) & (nullId == currLength)) { temp = temp.substring(0, nullId); } // deal with point (cut off if it is last char) if (temp.charAt(currLength) == '.') { temp = temp.substring(0, currLength); } out.content = (temp + "Z").getBytes(Charsets.UTF_8); out.length = ((byte[]) out.content).length; }
From source file:android.framework.org.apache.harmony.security_custom.asn1.ASN1StringType.java
public void setEncodingContent(BerOutputStream out) { byte[] bytes = ((String) out.content).getBytes(Charsets.UTF_8); out.content = bytes; out.length = bytes.length; }
From source file:fr.ens.biologie.genomique.eoulsan.it.ITCommandExecutor.java
/** * Execute a script from a command line retrieved from the test configuration. * @param scriptConfKey key for configuration to get command line * @param suffixNameOutputFile suffix for standard and error output file on * process//from w w w. j a va 2s. c o m * @param desc description on command line * @param isApplicationCmdLine true if application to run, otherwise false * corresponding to annexes script * @return result of execution command line, if command line not found in * configuration return null */ public ITCommandResult executeCommand(final String scriptConfKey, final String suffixNameOutputFile, final String desc, final boolean isApplicationCmdLine) { if (this.testConf.getProperty(scriptConfKey) == null) { return null; } // Get command line from the configuration final String cmdLine = this.testConf.getProperty(scriptConfKey); if (cmdLine.isEmpty()) { return null; } // Save command line in file if (isApplicationCmdLine) { try { com.google.common.io.Files.write(cmdLine + "\n", this.cmdLineFile, Charsets.UTF_8); } catch (final IOException e) { getLogger().warning("Error while writing the application command line in file: " + e.getMessage()); } } // Define stdout and stderr file final File stdoutFile = createSdtoutFile(suffixNameOutputFile); final File stderrFile = createSdterrFile(suffixNameOutputFile); int exitValue = -1; final Stopwatch timer = Stopwatch.createStarted(); final ITCommandResult cmdResult = new ITCommandResult(cmdLine, this.outputTestDirectory, desc, durationMax); try { final Process p = Runtime.getRuntime().exec(cmdLine, this.environmentVariables, this.outputTestDirectory); // Init monitor and start final MonitorThread monitor = new MonitorThread(p, desc, durationMax); // Save stdout if (stdoutFile != null) { new CopyProcessOutput(p.getInputStream(), stdoutFile, "stdout").start(); } // Save stderr if (stderrFile != null) { new CopyProcessOutput(p.getErrorStream(), stderrFile, "stderr").start(); } // Wait the end of the process exitValue = p.waitFor(); // Stop monitor thread monitor.interrupt(); cmdResult.setExitValue(exitValue); // Execution script fail, create an exception if (exitValue != 0) { if (monitor.isKilledProcess()) { cmdResult.asInterruptedProcess(); cmdResult.setException( new EoulsanException("\tKill process.\n\tCommand line: " + cmdLine + "\n\tDirectory: " + this.outputTestDirectory + "\n\tMessage: " + monitor.getMessage())); } else { cmdResult.setException(new EoulsanException("\tCommand line: " + cmdLine + "\n\tDirectory: " + this.outputTestDirectory + "\n\tMessage: bad exit value: " + exitValue)); cmdResult.setErrorFileOnProcess(stderrFile); } } else if (exitValue == 0 && !isApplicationCmdLine) { // Success execution, remove standard and error output file if (!stdoutFile.delete()) { getLogger().warning("Unable to deleted stdout file: " + stdoutFile); } if (!stderrFile.delete()) { getLogger().warning("Unable to deleted stderr file: " + stdoutFile); } } } catch (IOException | InterruptedException e) { cmdResult.setException(e, "\tError before execution.\n\tCommand line: " + cmdLine + "\n\tDirectory: " + this.outputTestDirectory + "\n\tMessage: " + e.getMessage()); } finally { cmdResult.setDuration(timer.elapsed(TimeUnit.MILLISECONDS)); timer.stop(); } return cmdResult; }
From source file:co.cask.tigon.sql.ioserver.OutputServerSocketTest.java
@Test public void testStreamHeaderParser() throws InterruptedException, IOException { String outputName = "output"; GDATEncoder encoder = new GDATEncoder(); encoder.writeLong(3L);/* ww w .ja va 2s . c o m*/ encoder.writeString("Hello"); ByteArrayOutputStream out = new ByteArrayOutputStream(); encoder.writeTo(out); byte[] dataBytes = out.toByteArray(); OutputServerSocket outputServerSocket = new OutputServerSocket(serverFacotry, outputName, "SELECT foo FROM bar", new GDATRecordQueue()); outputServerSocket.startAndWait(); InetSocketAddress serverAddress = outputServerSocket.getSocketAddressMap().get(Constants.StreamIO.DATASINK); LOG.info("Server is running at {}", serverAddress); setupClientPipeline(); ChannelFuture future = clientBootstrap.connect(serverAddress); future.await(3, TimeUnit.SECONDS); Channel channel = future.getChannel(); String gdatHeader = new StreamInputHeader(outputName, testSchema).getStreamHeader(); List<Byte> gdatByteList = new ArrayList<Byte>(Bytes.asList(gdatHeader.getBytes(Charsets.UTF_8))); gdatByteList.addAll(new ArrayList<Byte>(Bytes.asList(dataBytes))); int partitionSize = 10; List<List<Byte>> byteChunks = Lists.newArrayList(); for (int i = 0; i < gdatByteList.size(); i += partitionSize) { byteChunks.add(gdatByteList.subList(i, i + Math.min(partitionSize, gdatByteList.size() - i))); } ChannelBuffer buffer; for (List<Byte> chunk : byteChunks) { buffer = ChannelBuffers.wrappedBuffer(ArrayUtils.toPrimitive(chunk.toArray(new Byte[chunk.size()]))); channel.write(buffer).await(); TimeUnit.MILLISECONDS.sleep(10); } TimeUnit.SECONDS.sleep(2); Assert.assertEquals(1, outputServerSocket.getDataRecordsReceived()); }
From source file:android.framework.util.jar.InitManifest.java
private void readValue() throws IOException { boolean lastCr = false; int mark = pos; int last = pos; valueBuffer.rewind();// w w w .j ava2s . c o m while (pos < buf.length) { byte next = buf[pos++]; switch (next) { case 0: throw new IOException("NUL character in a manifest"); case '\n': if (lastCr) { lastCr = false; } else { consecutiveLineBreaks++; } continue; case '\r': lastCr = true; consecutiveLineBreaks++; continue; case ' ': if (consecutiveLineBreaks == 1) { valueBuffer.write(buf, mark, last - mark); mark = pos; consecutiveLineBreaks = 0; continue; } } if (consecutiveLineBreaks >= 1) { pos--; break; } last = pos; } valueBuffer.write(buf, mark, last - mark); value = valueBuffer.toString(Charsets.UTF_8); }
From source file:android.framework.util.jar.Manifest.java
/** * Writes out the attribute information of the specified manifest to the * specified {@code OutputStream}//from ww w . ja v a 2 s.co m * * @param manifest * the manifest to write out. * @param out * The {@code OutputStream} to write to. * @throws IOException * If an error occurs writing the {@code Manifest}. */ static void write(Manifest manifest, OutputStream out) throws IOException { CharsetEncoder encoder = Charsets.UTF_8.newEncoder(); ByteBuffer buffer = ByteBuffer.allocate(LINE_LENGTH_LIMIT); String version = manifest.mainAttributes.getValue(Attributes.Name.MANIFEST_VERSION); if (version != null) { writeEntry(out, Attributes.Name.MANIFEST_VERSION, version, encoder, buffer); Iterator<?> entries = manifest.mainAttributes.keySet().iterator(); while (entries.hasNext()) { Attributes.Name name = (Attributes.Name) entries.next(); if (!name.equals(Attributes.Name.MANIFEST_VERSION)) { writeEntry(out, name, manifest.mainAttributes.getValue(name), encoder, buffer); } } } out.write(LINE_SEPARATOR); Iterator<String> i = manifest.getEntries().keySet().iterator(); while (i.hasNext()) { String key = i.next(); writeEntry(out, NAME_ATTRIBUTE, key, encoder, buffer); Attributes attrib = manifest.entries.get(key); Iterator<?> entries = attrib.keySet().iterator(); while (entries.hasNext()) { Attributes.Name name = (Attributes.Name) entries.next(); writeEntry(out, name, attrib.getValue(name), encoder, buffer); } out.write(LINE_SEPARATOR); } }
From source file:fr.ens.biologie.genomique.eoulsan.it.IT.java
/** * Save all environment variables in file. *//*from w ww . ja v a2 s . c om*/ private void saveEnvironmentVariable() { final File envFile = new File(this.outputTestDirectory, ENV_FILENAME); // Write in file if (!(this.environmentVariables == null || this.environmentVariables.size() == 0)) { // Convert to string final String envToString = Joiner.on("\n").join(this.environmentVariables); try { com.google.common.io.Files.write(envToString, envFile, Charsets.UTF_8); } catch (final IOException e) { getLogger().warning("Error while writing environment variables in file: " + e.getMessage()); } } }
From source file:no.difi.sdp.client.asice.archive.CreateZip.java
public Archive zipIt(List<AsicEAttachable> files) { ByteArrayOutputStream archive = null; ZipArchiveOutputStream zipOutputStream = null; try {//from ww w .j av a 2 s . c o m archive = new ByteArrayOutputStream(); zipOutputStream = new ZipArchiveOutputStream(archive); zipOutputStream.setEncoding(Charsets.UTF_8.name()); zipOutputStream.setMethod(ZipArchiveOutputStream.DEFLATED); for (AsicEAttachable file : files) { log.trace("Adding " + file.getFileName() + " to archive. Size in bytes before compression: " + file.getBytes().length); ZipArchiveEntry zipEntry = new ZipArchiveEntry(file.getFileName()); zipEntry.setSize(file.getBytes().length); zipOutputStream.putArchiveEntry(zipEntry); IOUtils.copy(new ByteArrayInputStream(file.getBytes()), zipOutputStream); zipOutputStream.closeArchiveEntry(); } zipOutputStream.finish(); zipOutputStream.close(); return new Archive(archive.toByteArray()); } catch (IOException e) { throw new RuntimeIOException(e); } finally { IOUtils.closeQuietly(archive); IOUtils.closeQuietly(zipOutputStream); } }
From source file:org.apache.hadoop.mapreduce.lib.input.RHadoopInputFormat.java
public RecordReader<LongWritable, Text> createRecordReader(InputSplit split, TaskAttemptContext context) throws IOException, InterruptedException { String delimiter = context.getConfiguration().get("textinputformat.record.delimiter"); byte[] recordDelimiterBytes = null; /* sharvanath : solve this issue */ // to be implemented if (null != delimiter) recordDelimiterBytes = delimiter.getBytes(Charsets.UTF_8); return new LineRecordReader(recordDelimiterBytes); }