处理MQTT消息
This commit is contained in:
@ -0,0 +1,52 @@
|
||||
package com.fuyuanshen.app.domain.vo;
|
||||
|
||||
import java.io.*;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.TimeZone;
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) throws IOException {
|
||||
|
||||
String[] availableIDs = TimeZone.getAvailableIDs();
|
||||
for (String id : availableIDs) {
|
||||
System.out.println(id);
|
||||
}
|
||||
|
||||
byte[] data = "hello, world!".getBytes(StandardCharsets.UTF_8);
|
||||
try (CountInputStream input = new CountInputStream(new ByteArrayInputStream(data))) {
|
||||
int n;
|
||||
while ((n = input.read()) != -1) {
|
||||
System.out.println((char)n);
|
||||
}
|
||||
System.out.println("Total read " + input.getBytesRead() + " bytes");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class CountInputStream extends FilterInputStream {
|
||||
private int count = 0;
|
||||
|
||||
CountInputStream(InputStream in) {
|
||||
super(in);
|
||||
}
|
||||
|
||||
public int getBytesRead() {
|
||||
return this.count;
|
||||
}
|
||||
|
||||
public int read() throws IOException {
|
||||
int n = in.read();
|
||||
if (n != -1) {
|
||||
this.count ++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
public int read(byte[] b, int off, int len) throws IOException {
|
||||
int n = in.read(b, off, len);
|
||||
if (n != -1) {
|
||||
this.count += n;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user