List of usage examples for io.netty.util AsciiString arrayOffset
public int arrayOffset()
From source file:com.linecorp.armeria.server.http.tomcat.TomcatService.java
License:Apache License
private static void convertHeaders(HttpHeaders headers, MimeHeaders cHeaders) { if (headers.isEmpty()) { return;//w w w. ja v a2 s . co m } for (Entry<AsciiString, String> e : headers) { final AsciiString k = e.getKey(); final String v = e.getValue(); if (k.isEmpty() || k.byteAt(0) == ':') { continue; } final MessageBytes cValue = cHeaders.addValue(k.array(), k.arrayOffset(), k.length()); final byte[] valueBytes = v.getBytes(StandardCharsets.US_ASCII); cValue.setBytes(valueBytes, 0, valueBytes.length); } }
From source file:com.linecorp.armeria.server.http.tomcat.TomcatServiceInvocationHandler.java
License:Apache License
private static void convertHeaders(HttpHeaders headers, MimeHeaders cHeaders) { if (headers.isEmpty()) { return;/*w w w. j av a 2 s . com*/ } for (Iterator<Entry<CharSequence, CharSequence>> i = headers.iteratorCharSequence(); i.hasNext();) { final Entry<CharSequence, CharSequence> e = i.next(); final CharSequence k = e.getKey(); final CharSequence v = e.getValue(); final MessageBytes cValue; if (k instanceof AsciiString) { final AsciiString ak = (AsciiString) k; cValue = cHeaders.addValue(ak.array(), ak.arrayOffset(), ak.length()); } else { cValue = cHeaders.addValue(k.toString()); } if (v instanceof AsciiString) { final AsciiString av = (AsciiString) v; cValue.setBytes(av.array(), av.arrayOffset(), av.length()); } else { final byte[] valueBytes = v.toString().getBytes(StandardCharsets.US_ASCII); cValue.setBytes(valueBytes, 0, valueBytes.length); } } }
From source file:io.grpc.netty.GrpcHpackUtil.java
License:Apache License
/** * Compare two {@link CharSequence} objects without leaking timing information. * <p>//from w w w .j a va 2s .co m * The {@code int} return type is intentional and is designed to allow cascading of constant time operations: * <pre> * String s1 = "foo"; * String s2 = "foo"; * String s3 = "foo"; * String s4 = "goo"; * boolean equals = (equalsConstantTime(s1, s2) & equalsConstantTime(s3, s4)) != 0; * </pre> * @param s1 the first value. * @param s2 the second value. * @return {@code 0} if not equal. {@code 1} if equal. */ static int equalsConstantTime(CharSequence s1, CharSequence s2) { if (s1 instanceof AsciiString && s2 instanceof AsciiString) { if (s1.length() != s2.length()) { return 0; } AsciiString s1Ascii = (AsciiString) s1; AsciiString s2Ascii = (AsciiString) s2; return PlatformDependent.equalsConstantTime(s1Ascii.array(), s1Ascii.arrayOffset(), s2Ascii.array(), s2Ascii.arrayOffset(), s1.length()); } return ConstantTimeUtils.equalsConstantTime(s1, s2); }