use of java.io.DataInputStream in project che by eclipse.
the class DeltaProcessingState method getExternalLibTimeStamps.
public Hashtable getExternalLibTimeStamps() {
if (this.externalTimeStamps == null) {
Hashtable timeStamps = new Hashtable();
File timestampsFile = getTimeStampsFile();
DataInputStream in = null;
try {
in = new DataInputStream(new BufferedInputStream(new FileInputStream(timestampsFile)));
int size = in.readInt();
while (size-- > 0) {
String key = in.readUTF();
long timestamp = in.readLong();
timeStamps.put(Path.fromPortableString(key), new Long(timestamp));
}
} catch (IOException e) {
if (timestampsFile.exists())
//$NON-NLS-1$
Util.log(e, "Unable to read external time stamps");
} finally {
if (in != null) {
try {
in.close();
} catch (IOException e) {
// nothing we can do: ignore
}
}
}
this.externalTimeStamps = timeStamps;
}
return this.externalTimeStamps;
}
use of java.io.DataInputStream in project hadoop by apache.
the class ContainerTokenIdentifierForTest method readFields.
@Override
public void readFields(DataInput in) throws IOException {
DataInputStream dis = (DataInputStream) in;
byte[] buffer = IOUtils.toByteArray(dis);
proto = ContainerTokenIdentifierForTestProto.parseFrom(buffer);
}
use of java.io.DataInputStream in project hadoop by apache.
the class NMTokenIdentifierNewForTest method readFields.
@Override
public void readFields(DataInput in) throws IOException {
DataInputStream dis = (DataInputStream) in;
byte[] buffer = IOUtils.toByteArray(dis);
proto = NMTokenIdentifierNewProto.parseFrom(buffer);
}
use of java.io.DataInputStream in project hbase by apache.
the class AccessControlLists method readPermissions.
/**
* Reads a set of permissions as {@link org.apache.hadoop.io.Writable} instances from the input
* stream.
*/
public static ListMultimap<String, TablePermission> readPermissions(byte[] data, Configuration conf) throws DeserializationException {
if (ProtobufUtil.isPBMagicPrefix(data)) {
int pblen = ProtobufUtil.lengthOfPBMagic();
try {
AccessControlProtos.UsersAndPermissions.Builder builder = AccessControlProtos.UsersAndPermissions.newBuilder();
ProtobufUtil.mergeFrom(builder, data, pblen, data.length - pblen);
return AccessControlUtil.toUserTablePermissions(builder.build());
} catch (IOException e) {
throw new DeserializationException(e);
}
} else {
// TODO: We have to re-write non-PB data as PB encoded. Otherwise we will carry old Writables
// forever (here and a couple of other places).
ListMultimap<String, TablePermission> perms = ArrayListMultimap.create();
try {
DataInput in = new DataInputStream(new ByteArrayInputStream(data));
int length = in.readInt();
for (int i = 0; i < length; i++) {
String user = Text.readString(in);
List<TablePermission> userPerms = readWritablePermissions(in, conf);
perms.putAll(user, userPerms);
}
} catch (IOException | ClassNotFoundException e) {
throw new DeserializationException(e);
}
return perms;
}
}
use of java.io.DataInputStream in project zookeeper by apache.
the class CnxManagerTest method testInitialMessage.
@Test
public void testInitialMessage() throws Exception {
InitialMessage msg;
ByteArrayOutputStream bos;
DataInputStream din;
DataOutputStream dout;
String hostport;
// message with bad protocol version
try {
// the initial message (without the protocol version)
hostport = "10.0.0.2:3888";
bos = new ByteArrayOutputStream();
dout = new DataOutputStream(bos);
// sid
dout.writeLong(5L);
dout.writeInt(hostport.getBytes().length);
dout.writeBytes(hostport);
// now parse it
din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
msg = InitialMessage.parse(-65530L, din);
Assert.fail("bad protocol version accepted");
} catch (InitialMessage.InitialMessageException ex) {
}
// message too long
try {
hostport = createLongString(1048576);
bos = new ByteArrayOutputStream();
dout = new DataOutputStream(bos);
// sid
dout.writeLong(5L);
dout.writeInt(hostport.getBytes().length);
dout.writeBytes(hostport);
din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
msg = InitialMessage.parse(QuorumCnxManager.PROTOCOL_VERSION, din);
Assert.fail("long message accepted");
} catch (InitialMessage.InitialMessageException ex) {
}
// bad hostport string
try {
hostport = "what's going on here?";
bos = new ByteArrayOutputStream();
dout = new DataOutputStream(bos);
// sid
dout.writeLong(5L);
dout.writeInt(hostport.getBytes().length);
dout.writeBytes(hostport);
din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
msg = InitialMessage.parse(QuorumCnxManager.PROTOCOL_VERSION, din);
Assert.fail("bad hostport accepted");
} catch (InitialMessage.InitialMessageException ex) {
}
// good message
try {
hostport = "10.0.0.2:3888";
bos = new ByteArrayOutputStream();
dout = new DataOutputStream(bos);
// sid
dout.writeLong(5L);
dout.writeInt(hostport.getBytes().length);
dout.writeBytes(hostport);
// now parse it
din = new DataInputStream(new ByteArrayInputStream(bos.toByteArray()));
msg = InitialMessage.parse(QuorumCnxManager.PROTOCOL_VERSION, din);
} catch (InitialMessage.InitialMessageException ex) {
Assert.fail(ex.toString());
}
}
Aggregations