List of usage examples for java.nio CharBuffer array
public final char[] array()
From source file:com.odiago.flumebase.io.CharBufferUtils.java
/** * Parses a CharSequence into a floating-point value. *//* w w w . jav a2 s . c om*/ public static float parseFloat(CharBuffer chars) throws ColumnParseException { try { return Float.valueOf(new String(chars.array())); } catch (NumberFormatException nfe) { throw new ColumnParseException(nfe); } }
From source file:com.odiago.flumebase.io.CharBufferUtils.java
/** * Parses a CharSequence into a double-precision floating-point value. *///from ww w . j a va 2 s. c om public static double parseDouble(CharBuffer chars) throws ColumnParseException { try { return Double.valueOf(new String(chars.array())); } catch (NumberFormatException nfe) { throw new ColumnParseException(nfe); } }
From source file:com.silverpeas.ical.StringUtils.java
static char[] decodeToArray(byte[] bytes, Charset encoding) { if (CharEncoding.US_ASCII.equals(encoding.name())) { char[] array = new char[bytes.length]; for (int i = 0; i < array.length; i++) { array[i] = (char) bytes[i]; }/*w w w . j a v a 2s. c o m*/ return array; } try { CharBuffer buffer = encoding.newDecoder().decode(ByteBuffer.wrap(bytes)); char[] array = new char[buffer.limit()]; System.arraycopy(buffer.array(), 0, array, 0, array.length); return array; } catch (Exception nioException) { return (new String(bytes, encoding)).toCharArray(); } }
From source file:com.bconomy.autobit.Encryption.java
private static byte[] charsToBytes(char[] chars) { CharBuffer charBuffer = CharBuffer.wrap(chars); ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer); byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); Arrays.fill(charBuffer.array(), '\u0000'); // clear sensitive data Arrays.fill(byteBuffer.array(), (byte) 0); // clear sensitive data Arrays.fill(chars, '\u0000'); // clear sensitive data return bytes; }
From source file:io.alicorn.server.http.LoginEndpoint.java
public static String hash(char[] chars) { //Parse chars into bytes for hashing. CharBuffer charBuffer = CharBuffer.wrap(chars); ByteBuffer byteBuffer = charset.encode(charBuffer); byte[] bytes = Arrays.copyOfRange(byteBuffer.array(), byteBuffer.position(), byteBuffer.limit()); //Clear temporary arrays of any data. Arrays.fill(charBuffer.array(), '\u0000'); Arrays.fill(byteBuffer.array(), (byte) 0); //Generate the SHA-256 hash. String hash = hash(bytes);// ww w . j av a 2s. c o m //Clear remaining arrays of any data. Arrays.fill(bytes, (byte) 0); return hash; }
From source file:LoggingReader.java
@Override public int read(CharBuffer target) throws IOException { int read = theBase.read(target); if (theLog != null) theLog.write(target.array(), 0, read); else/*www.ja v a2 s. com*/ System.out.print(target.toString().substring(0, read)); return read; }
From source file:gdv.xport.io.RecyclingInputStreamReaderTest.java
/** * Test-Methode fuer {@link RecyclingInputStreamReader#skip(long)} und * {@link RecyclingInputStreamReader#read(CharBuffer)}. * * @throws IOException Signals that an I/O exception has occurred. */// ww w . j av a 2 s. com @Test public void testSkip() throws IOException { RecyclingInputStreamReader reader = new RecyclingInputStreamReader(istream, "ASCII"); try { reader.skip(1L); CharBuffer cbuf = CharBuffer.allocate(HELLO.length()); reader.read(cbuf); assertEquals(HELLO.substring(1), new String(cbuf.array()).trim()); } finally { reader.close(); } }
From source file:it.tidalwave.northernwind.frontend.ui.component.DefaultStaticHtmlFragmentViewController.java
protected void populate(final @Nonnull String htmlResourceName, final @Nonnull Map<String, String> attributes) throws IOException { final Resource htmlResource = new ClassPathResource(htmlResourceName, getClass()); final @Cleanup Reader r = new InputStreamReader(htmlResource.getInputStream()); final CharBuffer charBuffer = CharBuffer.allocate((int) htmlResource.contentLength()); final int length = r.read(charBuffer); r.close();// w w w . j av a2 s. co m final String html = new String(charBuffer.array(), 0, length); ST template = new ST(html, '$', '$'); for (final Entry<String, String> entry : attributes.entrySet()) { template = template.add(entry.getKey(), entry.getValue()); } view.setContent(template.render()); }
From source file:ape.NetworkDisconnectCommand.java
/** * This method writes to the Stand output *///from w w w . j ava 2s.co m private boolean writeSTDOut(Process p) { BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream())); int count; CharBuffer cbuf = CharBuffer.allocate(99999); try { count = stdInput.read(cbuf); if (count != -1) cbuf.array()[count] = '\0'; else if (cbuf.array()[0] != '\0') count = cbuf.array().length; else count = 0; for (int i = 0; i < count; i++) System.out.print(cbuf.get(i)); } catch (IOException e) { System.err.println( "Writing Stdout in NetworkDisconnectCommand catches an exception, Turn on the VERBOSE flag to see the stack trace"); e.printStackTrace(); return false; } try { stdInput.close(); } catch (IOException e) { System.err.println("Unable to close the IOStream"); e.printStackTrace(); return false; } return true; }
From source file:com.twentyn.patentScorer.PatentScorer.java
@Override public void processPatentText(File patentFile, Reader patentTextReader, int patentTextLength) throws IOException, ParserConfigurationException, SAXException, TransformerConfigurationException, TransformerException, XPathExpressionException { System.out.println("Patent text length: " + patentTextLength); CharBuffer buff = CharBuffer.allocate(patentTextLength); int read = patentTextReader.read(buff); System.out.println("Read bytes: " + read); patentTextReader.reset();//from w ww . j ava 2 s . c o m String fullContent = new String(buff.array()); PatentDocument patentDocument = PatentDocument .patentDocumentFromXMLStream(new ReaderInputStream(patentTextReader, Charset.forName("utf-8"))); if (patentDocument == null) { LOGGER.info("Found non-patent type document, skipping."); return; } double pr = this.patentModel.ProbabilityOf(fullContent); this.outputWriter .write(objectMapper.writeValueAsString(new ClassificationResult(patentDocument.getFileId(), pr))); this.outputWriter.write(LINE_SEPARATOR); System.out.println("Doc " + patentDocument.getFileId() + " has score " + pr); }