Java Code Examples for org.apache.rocketmq.common.UtilAll#string2bytes()
The following examples show how to use
org.apache.rocketmq.common.UtilAll#string2bytes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MessageClientIDSetter.java From rocketmq-4.3.0 with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 2
Source File: MessageClientIDSetter.java From rocketmq-read with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 3
Source File: MessageClientIDSetter.java From rocketmq with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); int ipLength = bytes.length == 28 ? 16 : 4; buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put(bytes, ipLength + 2 + 4, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 4
Source File: MessageClientIDSetter.java From rocketmq with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); buf.put((byte)0); buf.put((byte)0); buf.put((byte)0); buf.put((byte)0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 5
Source File: MessageClientIDSetter.java From DDMQ with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 6
Source File: MessageClientIDSetter.java From DDMQ with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 7
Source File: Test.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
public static void main(String[] args) { String msgId = "AC1303C20010034B1D80986D3F547F09"; try { byte[] ip = UtilAll.string2bytes(msgId.substring(0, 8)); byte[] port = UtilAll.string2bytes(msgId.substring(8, 16)); ByteBuffer bb = ByteBuffer.wrap(port); int portInt = bb.getInt(0); // offset byte[] data = UtilAll.string2bytes(msgId.substring(16, 32)); bb = ByteBuffer.wrap(data); long offset = bb.getLong(0); System.out.println(); System.out.printf(InetAddress.getByAddress(ip)+"======="+portInt+">>>>>>"+offset); } catch (Exception e) { e.printStackTrace(); } }
Example 8
Source File: MessageClientIDSetter.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR_OF_DAY, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 9
Source File: MessageClientIDSetter.java From rocketmq_trans_message with Apache License 2.0 | 6 votes |
public static Date getNearlyTimeFromID(String msgID) { ByteBuffer buf = ByteBuffer.allocate(8); byte[] bytes = UtilAll.string2bytes(msgID); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put((byte) 0); buf.put(bytes, 10, 4); buf.position(0); long spanMS = buf.getLong(); Calendar cal = Calendar.getInstance(); long now = cal.getTimeInMillis(); cal.set(Calendar.DAY_OF_MONTH, 1); cal.set(Calendar.HOUR, 0); cal.set(Calendar.MINUTE, 0); cal.set(Calendar.SECOND, 0); cal.set(Calendar.MILLISECOND, 0); long monStartTime = cal.getTimeInMillis(); if (monStartTime + spanMS >= now) { cal.add(Calendar.MONTH, -1); monStartTime = cal.getTimeInMillis(); } cal.setTimeInMillis(monStartTime + spanMS); return cal.getTime(); }
Example 10
Source File: MessageClientIDSetter.java From rocketmq with Apache License 2.0 | 5 votes |
public static byte[] getIPFromID(String msgID) { byte[] bytes = UtilAll.string2bytes(msgID); int ipLength = bytes.length == 28 ? 16 : 4; byte[] result = new byte[ipLength]; System.arraycopy(bytes, 0, result, 0, ipLength); return result; }
Example 11
Source File: MessageClientIDSetter.java From DDMQ with Apache License 2.0 | 4 votes |
public static byte[] getIPFromID(String msgID) { byte[] result = new byte[4]; byte[] bytes = UtilAll.string2bytes(msgID); System.arraycopy(bytes, 0, result, 0, 4); return result; }
Example 12
Source File: MessageClientIDSetter.java From rocketmq with Apache License 2.0 | 4 votes |
public static int getPidFromID(String msgID) { byte[] bytes = UtilAll.string2bytes(msgID); ByteBuffer wrap = ByteBuffer.wrap(bytes); int value = wrap.getShort(bytes.length - 2 - 4 - 4 - 2); return value & 0x0000FFFF; }
Example 13
Source File: MessageClientIDSetter.java From rocketmq_trans_message with Apache License 2.0 | 4 votes |
public static byte[] getIPFromID(String msgID) { byte[] result = new byte[4]; byte[] bytes = UtilAll.string2bytes(msgID); System.arraycopy(bytes, 0, result, 0, 4); return result; }
Example 14
Source File: MessageClientIDSetter.java From rocketmq-all-4.1.0-incubating with Apache License 2.0 | 4 votes |
public static byte[] getIPFromID(String msgID) { byte[] result = new byte[4]; byte[] bytes = UtilAll.string2bytes(msgID); System.arraycopy(bytes, 0, result, 0, 4); return result; }
Example 15
Source File: MessageClientIDSetter.java From rocketmq with Apache License 2.0 | 4 votes |
public static byte[] getIPFromID(String msgID) { byte[] result = new byte[4]; byte[] bytes = UtilAll.string2bytes(msgID); System.arraycopy(bytes, 0, result, 0, 4); return result; }
Example 16
Source File: MessageClientIDSetter.java From rocketmq-read with Apache License 2.0 | 4 votes |
public static byte[] getIPFromID(String msgID) { byte[] result = new byte[4]; byte[] bytes = UtilAll.string2bytes(msgID); System.arraycopy(bytes, 0, result, 0, 4); return result; }
Example 17
Source File: MessageClientIDSetter.java From rocketmq-4.3.0 with Apache License 2.0 | 4 votes |
public static byte[] getIPFromID(String msgID) { byte[] result = new byte[4]; byte[] bytes = UtilAll.string2bytes(msgID); System.arraycopy(bytes, 0, result, 0, 4); return result; }
Example 18
Source File: MessageClientIDSetter.java From DDMQ with Apache License 2.0 | 4 votes |
public static byte[] getIPFromID(String msgID) { byte[] result = new byte[4]; byte[] bytes = UtilAll.string2bytes(msgID); System.arraycopy(bytes, 0, result, 0, 4); return result; }