Search in sources :

Example 6 with DataInputStream

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;
}
Also used : BufferedInputStream(java.io.BufferedInputStream) Hashtable(java.util.Hashtable) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 7 with DataInputStream

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);
}
Also used : DataInputStream(java.io.DataInputStream)

Example 8 with DataInputStream

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);
}
Also used : DataInputStream(java.io.DataInputStream)

Example 9 with DataInputStream

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;
    }
}
Also used : IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException) DataInput(java.io.DataInput) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 10 with DataInputStream

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());
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DataOutputStream(java.io.DataOutputStream) InitialMessage(org.apache.zookeeper.server.quorum.QuorumCnxManager.InitialMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DataInputStream(java.io.DataInputStream) Test(org.junit.Test)

Aggregations

DataInputStream (java.io.DataInputStream)2761 ByteArrayInputStream (java.io.ByteArrayInputStream)1139 IOException (java.io.IOException)1043 DataOutputStream (java.io.DataOutputStream)606 FileInputStream (java.io.FileInputStream)542 Test (org.junit.Test)533 ByteArrayOutputStream (java.io.ByteArrayOutputStream)368 File (java.io.File)274 BufferedInputStream (java.io.BufferedInputStream)253 InputStream (java.io.InputStream)245 ArrayList (java.util.ArrayList)200 EOFException (java.io.EOFException)154 DataInput (java.io.DataInput)141 FileNotFoundException (java.io.FileNotFoundException)131 ByteBuffer (java.nio.ByteBuffer)119 FileOutputStream (java.io.FileOutputStream)105 HashMap (java.util.HashMap)101 BufferedReader (java.io.BufferedReader)90 InputStreamReader (java.io.InputStreamReader)89 Socket (java.net.Socket)75