List of usage examples for java.nio CharBuffer wrap
public static CharBuffer wrap(CharSequence chseq)
From source file:com.kotcrab.vis.editor.module.editor.AnalyticsModule.java
public static int truncateUtf8(String input, byte[] output) { ByteBuffer outBuf = ByteBuffer.wrap(output); CharBuffer inBuf = CharBuffer.wrap(input.toCharArray()); Charset utf8 = Charset.forName("UTF-8"); utf8.newEncoder().encode(inBuf, outBuf, true); return outBuf.position(); }
From source file:ch.cyberduck.core.http.DelayedHttpMultipartEntity.java
private static ByteArrayBuffer encode(final Charset charset, final String input) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(input)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab;/*from w ww . j a v a 2 s . c om*/ }
From source file:org.sonar.api.batch.fs.internal.charhandler.LineHashComputer.java
private void processBuffer() { try {/*w ww .j av a 2 s . c o m*/ if (sb.length() > 0) { ByteBuffer encoded = encoder.encode(CharBuffer.wrap(sb)); lineMd5Digest.update(encoded.array(), 0, encoded.limit()); consumer.consume(line, lineMd5Digest.digest()); } } catch (CharacterCodingException e) { throw new IllegalStateException("Error encoding line hash in file: " + file.getAbsolutePath(), e); } }
From source file:com.mcxiaoke.next.http.entity.mime.AbstractMultipartForm.java
private static ByteArrayBuffer encode(final Charset charset, final String string) { final ByteBuffer encoded = charset.encode(CharBuffer.wrap(string)); final ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining()); bab.append(encoded.array(), encoded.position(), encoded.remaining()); return bab;//from ww w. ja va 2 s . com }
From source file:io.mandrel.requests.proxy.AuthenticatorUtils.java
public static String computeDigestAuthentication(Realm realm) { StringBuilder builder = new StringBuilder().append("Digest "); append(builder, "username", realm.getPrincipal(), true); append(builder, "realm", realm.getRealmName(), true); append(builder, "nonce", realm.getNonce(), true); append(builder, "uri", computeRealmURI(realm), true); if (StringUtils.isNotEmpty(realm.getAlgorithm())) append(builder, "algorithm", realm.getAlgorithm(), false); append(builder, "response", realm.getResponse(), true); if (realm.getOpaque() != null) append(builder, "opaque", realm.getOpaque(), true); if (realm.getQop() != null) { append(builder, "qop", realm.getQop(), false); // nc and cnonce only sent if server sent qop append(builder, "nc", realm.getNc(), false); append(builder, "cnonce", realm.getCnonce(), true); }/*from w w w . ja va 2s . c o m*/ builder.setLength(builder.length() - 2); // remove tailing ", " // FIXME isn't there a more efficient way? return new String(ISO_8859_1.encode(CharBuffer.wrap(builder)).toString()); }
From source file:com.acciente.oacc.encryptor.jasypt.LegacyJasyptPasswordEncryptor.java
private byte[] getCleanedBytes(char[] password) { final char[] normalizedChars = TextNormalizer.getInstance().normalizeToNfc(password); final ByteBuffer byteBuffer = StandardCharsets.UTF_8.encode(CharBuffer.wrap(normalizedChars)); final byte[] byteArray = new byte[byteBuffer.remaining()]; byteBuffer.get(byteArray);/*from www . jav a 2 s . c o m*/ Arrays.fill(byteBuffer.array(), (byte) 0); return byteArray; }
From source file:org.dishevelled.bio.alignment.sam.SamReaderTest.java
@Before public void setUp() { readable = CharBuffer.wrap("@HD\tVN:1.5\tSO:coordinate"); emptyReadable = CharBuffer.wrap(""); parseListener = new SamParseAdapter(); streamListener = new SamStreamAdapter(); }
From source file:org.richfaces.request.FileUploadValueParamTest.java
@Test public void testLongParam() throws Exception { StringBuilder sb = new StringBuilder(); CharsetEncoder charsetEncoder = Charset.forName("UTF-8").newEncoder(); for (int i = 0; i < 256; i++) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); int count = new Random().nextInt(128) + 128; while (count != 0) { char c = (char) new Random().nextInt(Character.MAX_VALUE); if (charsetEncoder.canEncode(c)) { baos.write(charsetEncoder.encode(CharBuffer.wrap(new char[] { c })).array()); count--;/*from ww w . ja v a 2s. c o m*/ } } byte[] bs = baos.toByteArray(); param.handle(bs, bs.length); sb.append(new String(bs, "UTF-8")); } param.complete(); assertEquals(sb.toString(), param.getValue()); }
From source file:org.opencb.hpg.bigdata.core.io.VcfBlockIterator.java
public List<CharBuffer> next(long blockSize) { long cnt = 0L; List<CharBuffer> next = new LinkedList<>(); // linked list faster at creation time while (iter.hasNext() && cnt < blockSize) { String line = iter.next(); CharBuffer buff = CharBuffer.wrap(line.toCharArray()); //FIXME! Avoid char array copy next.add(buff);/*from w w w .j a va 2 s . c om*/ cnt += buff.length(); } return next; }
From source file:sh.isaac.provider.sync.git.gitblit.utils.ConnectionUtils.java
/** * To bytes./*ww w.jav a 2 s . c om*/ * * @param chars the chars * @return the byte[] */ private static byte[] toBytes(char[] chars) { final CharBuffer charBuffer = CharBuffer.wrap(chars); final ByteBuffer byteBuffer = Charset.forName("UTF-8").encode(charBuffer); final 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 return bytes; }