In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/03 Report--
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.ShortWritable;
import org.junit.Test;
public class TestWritable {
/*
* test writable
*/
@Test
public void test1() throws Exception {
IntWritable age = new IntWritable();
age.set(163);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DataOutputStream dataOut = new DataOutputStream(baos);
//serialize
age.write(dataOut);
dataOut.close();
byte[] bts = baos.toByteArray();
for (byte by : bts) {
System.out.println(by);
}
System.out.println(bts.toString());
//deserialize
IntWritable age2 = new IntWritable();
age2.readFields(new DataInputStream(new ByteArrayInputStream(baos
.toByteArray())));
System.out.println(age2.get());
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
DataInputStream dis = new DataInputStream(bais);
System.out.println(dis.readInt());
// //test reading in short type mode
// ShortWritable short1 = new ShortWritable();
// short1.readFields(dis);
// System.out.println(short1.get());
// ShortWritable short2 = new ShortWritable();
// short2.readFields(dis);
// System.out.println(short2.get());
}
}
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.