/** @see org.mulgara.store.stringpool.SPObject#getData() */ public ByteBuffer getData() { ByteBuffer data = CHARSET.encode(lexical); // if this is the same size as a long, expand it and pad it if (data.limit() == END_IDX) { ByteBuffer newData = ByteBuffer.allocate(END_IDX + 1); newData.put(data); newData.put(END_IDX, END_BYTE); newData.rewind(); data = newData; } return data; }
/** * Creates an xsd:decimal by decoding from a data buffer. * * @param subtypeId The ID for either the full or abbreviated xsd:decimal. * @param typeURI The full or abbreviated URI for xsd:decimal. * @param data The data containing the xsd:decimal value. */ SPDecimalBaseImpl(int subtypeId, URI typeURI, ByteBuffer data) { super(subtypeId, typeURI); if (data.limit() == Constants.SIZEOF_LONG) throw new IllegalArgumentException("Buffer does not hold a decimal."); ByteBuffer number = data; if (data.limit() == END_IDX + 1) { if (data.get(END_IDX) == END_BYTE) { data.limit(END_IDX); number = data.slice(); } } lexical = CHARSET.decode(number).toString(); val = new BigDecimal(lexical); }
/** * Reads a byte buffer and converts to a BigDecimal, regardless of formatting. * * @param bb The byte buffer to decode. * @return A BigDecimal representing the stored number. */ static BigDecimal decode(ByteBuffer bb) { ByteBuffer number = bb; int limit = bb.limit(); if (limit == Constants.SIZEOF_LONG) return BigDecimal.valueOf(bb.getLong()); if (limit == END_IDX + 1) { // is this buffer padded? byte terminator = bb.get(END_IDX); if (terminator == SPDecimalBaseImpl.END_BYTE) { // remove the padding bb.limit(END_IDX); number = bb.slice(); } } return new BigDecimal(CHARSET.decode(number).toString()); }
private static final String getCharset(String mimeType) { if (mimeType != null) { Matcher m = CHARSET.matcher(mimeType); if (m.find()) { String charset = m.group(1); if (charset.length() >= 2 && charset.charAt(0) == '"' && charset.charAt(charset.length() - 1) == '"') { charset = charset.substring(1, charset.length() - 1); charset = charset.replace("\\\"", "\""); } return charset; } } return DEFAULT_CHARSET; }
UnknownSPTypedLiteralImpl(ByteBuffer data) { super(TYPE_ID, null); // Split the buffer into the datatype and lexical form fields String string = CHARSET.decode(data).toString(); int delimiter = string.indexOf('\t'); if (delimiter == -1) { throw new RuntimeException("Corrupt string pool entry (no delimiter)"); } try { // Initialize instance fields this.lexicalForm = string.substring(delimiter + 1, string.length()); this.typeURI = new URI(string.substring(0, delimiter)); } catch (URISyntaxException e) { throw new RuntimeException("Corrupt string pool entry", e); } }
public void setHeaders(Map<String, String> headers) { String h = headers.get("host"); if (h != null) { int idx = h.lastIndexOf(':'); if (idx != -1) { this.serverName = h.substring(0, idx); serverPort = Integer.valueOf(h.substring(idx + 1)); } else { this.serverName = h; } } String ct = headers.get(CONTENT_TYPE); if (ct != null) { int idx = ct.indexOf(";"); if (idx != -1) { int cidx = ct.indexOf(CHARSET, idx); if (cidx != -1) { contentType = ct.substring(0, idx); charset = ct.substring(cidx + CHARSET.length()); } else { contentType = ct; } } else { contentType = ct; } } String con = headers.get(CONNECTION); if (con != null) { con = con.toLowerCase(); } isKeepAlive = (version == HTTP_1_1 && !"close".equals(con)) || "keep-alive".equals(con); isWebSocket = "websocket".equalsIgnoreCase(headers.get("upgrade")); this.headers = headers; }
public ByteBuffer getData() { assert typeURI.toString().indexOf('\t') == -1 : "Datatype URI contains tab: " + typeURI; return CHARSET.encode(typeURI + "\t" + lexicalForm); }