public static String bytesToHex(byte[] bs) { if (bs == null) { return null; } return bytesToHex(bs, 0, bs.length); }
@Override public String toString() { return MessageFormat.format("Message[type={0}, priority={1}, data={3}]", type, priority, HexUtil.bytesToHex(data)); }
@Override public String toString() { return MessageFormat.format("Message[type={0}, priority={1}, data={3}]", type, priority, HexUtil.bytesToHex(data)); }
@Override public String toString() { return MessageFormat.format("{0}[id={1}, size={2}]", getClass().getSimpleName(), HexUtil.bytesToHex(id), size); } }
public static String createDurableLockingID(int bytes) { byte[] buffer = new byte[bytes]; Random random = new Random(System.currentTimeMillis()); random.nextBytes(buffer); return HexUtil.bytesToHex(buffer); } }
public synchronized void queryLobs(List<byte[]> ids) { for (Iterator<byte[]> it = ids.iterator(); it.hasNext();) { byte[] id = it.next(); String key = HexUtil.bytesToHex(id); if (!lobs.containsKey(key)) { it.remove(); } } }
public synchronized void writeClob(byte[] id, long size, Reader reader) throws IOException { CharArrayWriter out = new CharArrayWriter(); IOUtil.copyCharacter(reader, out, size); lobs.put(HexUtil.bytesToHex(id), out.toCharArray()); }
public File getCharacterFile(byte[] id) { return new File(getFolder(), HexUtil.bytesToHex(id) + ".clob"); }
public synchronized void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); IOUtil.copyBinary(inputStream, out, size); lobs.put(HexUtil.bytesToHex(id), out.toByteArray()); }
@Override protected String getString() { return HexUtil.bytesToHex(getValue()); }
public File getBinaryFile(byte[] id) { return new File(getFolder(), HexUtil.bytesToHex(id) + ".blob"); }
protected boolean showLob(PrintStream out, String type, byte[] id, long size, CDOServerBrowser browser, String param) { String hex = HexUtil.bytesToHex(id); boolean selected = hex.equals(param); String label = selected ? hex : browser.href(hex, getName(), "id", hex); out.println(type + " " + label + " (" + size + ")"); return selected; } }
@Override protected void doSetValue(PreparedStatement stmt, int index, Object value) throws SQLException { CDOClob clob = (CDOClob)value; stmt.setString(index, HexUtil.bytesToHex(clob.getID()) + "-" + clob.getSize()); }
@Override protected void doSetValue(PreparedStatement stmt, int index, Object value) throws SQLException { CDOBlob blob = (CDOBlob)value; stmt.setString(index, HexUtil.bytesToHex(blob.getID()) + "-" + blob.getSize()); }
@Override public void write(byte[] b, int off, int len) throws IOException { try { char[] cbuf = HexUtil.bytesToHex(b, off, len).toCharArray(); xmlHandler.characters(cbuf, 0, cbuf.length); } catch (SAXException ex) { throw WrappedException.wrap(ex); } }
public synchronized void loadLob(byte[] id, OutputStream out) throws IOException { String key = HexUtil.bytesToHex(id); Object lob = lobs.get(key); if (lob == null) { throw new IOException("Lob not found: " + key); } if (lob instanceof byte[]) { byte[] blob = (byte[])lob; ByteArrayInputStream in = new ByteArrayInputStream(blob); IOUtil.copyBinary(in, out, blob.length); } else { char[] clob = (char[])lob; CharArrayReader in = new CharArrayReader(clob); IOUtil.copyCharacter(in, new OutputStreamWriter(out), clob.length); } }
@Override protected Writer startClob(XMLOutput out, byte[] id, long size) throws Exception { out.element(CLOB); out.attribute(LOB_ID, HexUtil.bytesToHex(id)); out.attribute(LOB_SIZE, size); return out.characters(); }
@Override protected OutputStream startBlob(XMLOutput out, byte[] id, long size) throws Exception { out.element(BLOB); out.attribute(LOB_ID, HexUtil.bytesToHex(id)); out.attribute(LOB_SIZE, size); return out.bytes(); }
@Override protected void writeBlob(byte[] id, long size, InputStream inputStream) throws IOException { IDBPreparedStatement stmt = connection.prepareStatement(CDODBSchema.SQL_WRITE_BLOB, ReuseProbability.MEDIUM); try { stmt.setString(1, HexUtil.bytesToHex(id)); stmt.setLong(2, size); stmt.setBinaryStream(3, inputStream, (int)size); DBUtil.update(stmt, true); } catch (SQLException ex) { throw new DBException(ex); } finally { DBUtil.close(stmt); } }
@Override protected void writeClob(byte[] id, long size, Reader reader) throws IOException { IDBPreparedStatement stmt = connection.prepareStatement(CDODBSchema.SQL_WRITE_CLOB, ReuseProbability.MEDIUM); try { stmt.setString(1, HexUtil.bytesToHex(id)); stmt.setLong(2, size); stmt.setCharacterStream(3, reader, (int)size); DBUtil.update(stmt, true); } catch (SQLException ex) { throw new DBException(ex); } finally { DBUtil.close(stmt); } }