Example usage for java.io DataInputStream readUTF

List of usage examples for java.io DataInputStream readUTF

Introduction

In this page you can find the example usage for java.io DataInputStream readUTF.

Prototype

public final String readUTF() throws IOException 

Source Link

Document

See the general contract of the readUTF method of DataInput.

Usage

From source file:com.yahoo.pulsar.testclient.LoadSimulationClient.java

private void handle(final byte command, final DataInputStream inputStream, final DataOutputStream outputStream)
        throws Exception {
    final TradeConfiguration tradeConf = new TradeConfiguration();
    tradeConf.command = command;//from ww  w  .j  a  v  a 2 s  .com
    switch (command) {
    case CHANGE_COMMAND:
        // Change the topic's settings if it exists. Report whether the
        // topic was found on this server.
        decodeProducerOptions(tradeConf, inputStream);
        if (topicsToTradeUnits.containsKey(tradeConf.topic)) {
            topicsToTradeUnits.get(tradeConf.topic).change(tradeConf);
            outputStream.write(FOUND_TOPIC);
        } else {
            outputStream.write(NO_SUCH_TOPIC);
        }
        break;
    case STOP_COMMAND:
        // Stop the topic if it exists. Report whether the topic was found,
        // and whether it was already stopped.
        tradeConf.topic = inputStream.readUTF();
        if (topicsToTradeUnits.containsKey(tradeConf.topic)) {
            final boolean wasStopped = topicsToTradeUnits.get(tradeConf.topic).stop.getAndSet(true);
            outputStream.write(wasStopped ? REDUNDANT_COMMAND : FOUND_TOPIC);
        } else {
            outputStream.write(NO_SUCH_TOPIC);
        }
        break;
    case TRADE_COMMAND:
        // Create the topic. It is assumed that the topic does not already
        // exist.
        decodeProducerOptions(tradeConf, inputStream);
        final TradeUnit tradeUnit = new TradeUnit(tradeConf, client, producerConf, consumerConf, payloadCache);
        topicsToTradeUnits.put(tradeConf.topic, tradeUnit);
        executor.submit(() -> {
            try {
                tradeUnit.start();
            } catch (Exception ex) {
                throw new RuntimeException(ex);
            }
        });
        // Tell controller topic creation is finished.
        outputStream.write(NO_SUCH_TOPIC);
        break;
    case CHANGE_GROUP_COMMAND:
        // Change the settings of all topics belonging to a group. Report
        // the number of topics changed.
        decodeGroupOptions(tradeConf, inputStream);
        tradeConf.size = inputStream.readInt();
        tradeConf.rate = inputStream.readDouble();
        // See if a topic belongs to this tenant and group using this regex.
        final String groupRegex = ".*://.*/" + tradeConf.tenant + "/" + tradeConf.group + "-.*/.*";
        int numFound = 0;
        for (Map.Entry<String, TradeUnit> entry : topicsToTradeUnits.entrySet()) {
            final String destination = entry.getKey();
            final TradeUnit unit = entry.getValue();
            if (destination.matches(groupRegex)) {
                ++numFound;
                unit.change(tradeConf);
            }
        }
        outputStream.writeInt(numFound);
        break;
    case STOP_GROUP_COMMAND:
        // Stop all topics belonging to a group. Report the number of topics
        // stopped.
        decodeGroupOptions(tradeConf, inputStream);
        // See if a topic belongs to this tenant and group using this regex.
        final String regex = ".*://.*/" + tradeConf.tenant + "/" + tradeConf.group + "-.*/.*";
        int numStopped = 0;
        for (Map.Entry<String, TradeUnit> entry : topicsToTradeUnits.entrySet()) {
            final String destination = entry.getKey();
            final TradeUnit unit = entry.getValue();
            if (destination.matches(regex) && !unit.stop.getAndSet(true)) {
                ++numStopped;
            }
        }
        outputStream.writeInt(numStopped);
        break;
    default:
        throw new IllegalArgumentException("Unrecognized command code received: " + command);
    }
    outputStream.flush();
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Deserializes a <code>NodePropBundle</code> from a data input stream.
 *
 * @param in the input stream//  ww w  .ja va  2 s.  c  o m
 * @param id the node id for the new bundle
 * @return the bundle
 * @throws IOException if an I/O error occurs.
 */
public NodePropBundle readBundle(DataInputStream in, NodeId id) throws IOException {

    NodePropBundle bundle = new NodePropBundle(this, id);

    // read version and primary type...special handling
    int index = in.readInt();

    // get version
    int version = (index >> 24) & 0xff;
    index &= 0x00ffffff;
    String uri = nsIndex.indexToString(index);
    String local = nameIndex.indexToString(in.readInt());
    Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local);

    // primaryType
    bundle.setNodeTypeName(nodeTypeName);

    // parentUUID
    bundle.setParentId(readID(in));

    // definitionId
    in.readUTF();

    // mixin types
    Set mixinTypeNames = new HashSet();
    Name name = readIndexedQName(in);
    while (name != null) {
        mixinTypeNames.add(name);
        name = readIndexedQName(in);
    }
    bundle.setMixinTypeNames(mixinTypeNames);

    // properties
    name = readIndexedQName(in);
    while (name != null) {
        PropertyId pId = new PropertyId(bundle.getId(), name);
        // skip redundant primaryType, mixinTypes and uuid properties
        if (name.equals(NameConstants.JCR_PRIMARYTYPE) || name.equals(NameConstants.JCR_MIXINTYPES)
                || name.equals(NameConstants.JCR_UUID)) {
            readPropertyEntry(in, pId);
            name = readIndexedQName(in);
            continue;
        }
        NodePropBundle.PropertyEntry pState = readPropertyEntry(in, pId);
        bundle.addProperty(pState);
        name = readIndexedQName(in);
    }

    // set referenceable flag
    bundle.setReferenceable(in.readBoolean());

    // child nodes (list of uuid/name pairs)
    NodeId childId = readID(in);
    while (childId != null) {
        bundle.addChildNodeEntry(readQName(in), childId);
        childId = readID(in);
    }

    // read modcount, since version 1.0
    if (version >= VERSION_1) {
        bundle.setModCount(readModCount(in));
    }

    // read shared set, since version 2.0
    Set sharedSet = new HashSet();
    if (version >= VERSION_2) {
        // shared set (list of parent uuids)
        NodeId parentId = readID(in);
        while (parentId != null) {
            sharedSet.add(parentId);
            parentId = readID(in);
        }
    }
    bundle.setSharedSet(sharedSet);

    return bundle;
}

From source file:org.openmrs.module.odkconnector.serialization.web.PatientWebConnectorTest.java

@Test
public void serialize_shouldDisplayAllPatientInformation() throws Exception {

    // compose url
    URL u = new URL(SERVER_URL + "/module/odkconnector/download/patients.form");

    // setup http url connection
    HttpURLConnection connection = (HttpURLConnection) u.openConnection();
    connection.setDoOutput(true);/*from w w w  . j av a 2  s .c  o  m*/
    connection.setRequestMethod("POST");
    connection.setConnectTimeout(10000);
    connection.setReadTimeout(10000);
    connection.addRequestProperty("Content-type", "application/octet-stream");

    // write auth details to connection
    DataOutputStream outputStream = new DataOutputStream(new GZIPOutputStream(connection.getOutputStream()));
    outputStream.writeUTF("admin");
    outputStream.writeUTF("test");
    outputStream.writeBoolean(true);
    outputStream.writeInt(2);
    outputStream.writeInt(1);
    outputStream.close();

    DataInputStream inputStream = new DataInputStream(new GZIPInputStream(connection.getInputStream()));
    Integer responseStatus = inputStream.readInt();

    ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream();

    int count = 0;
    byte[] buffer = new byte[1024];
    while ((count = inputStream.read(buffer)) > 0) {
        arrayOutputStream.write(buffer, 0, count);
    }
    arrayOutputStream.close();
    inputStream.close();

    File file = new File("/home/nribeka/connector.data");
    FileOutputStream fos = new FileOutputStream(file);
    fos.write(arrayOutputStream.toByteArray());
    fos.close();

    inputStream = new DataInputStream(new FileInputStream(file));

    if (responseStatus == HttpURLConnection.HTTP_OK) {

        // total number of patients
        Integer patientCounter = inputStream.readInt();
        System.out.println("Patient Counter: " + patientCounter);
        for (int j = 0; j < patientCounter; j++) {
            System.out.println("=================Patient=====================");
            System.out.println("Patient Id: " + inputStream.readInt());
            System.out.println("Family Name: " + inputStream.readUTF());
            System.out.println("Middle Name: " + inputStream.readUTF());
            System.out.println("Last Name: " + inputStream.readUTF());
            System.out.println("Gender: " + inputStream.readUTF());
            System.out.println("Birth Date: " + inputStream.readUTF());
            System.out.println("Identifier: " + inputStream.readUTF());
            System.out.println("Patients: " + j + " out of " + patientCounter);
        }

        Integer obsCounter = inputStream.readInt();
        System.out.println("Observation Counter: " + obsCounter);
        for (int j = 0; j < obsCounter; j++) {
            System.out.println("==================Observation=================");
            System.out.println("Patient Id: " + inputStream.readInt());
            System.out.println("Concept Name: " + inputStream.readUTF());

            byte type = inputStream.readByte();
            if (type == ObsSerializer.TYPE_STRING)
                System.out.println("Value: " + inputStream.readUTF());
            else if (type == ObsSerializer.TYPE_INT)
                System.out.println("Value: " + inputStream.readInt());
            else if (type == ObsSerializer.TYPE_DOUBLE)
                System.out.println("Value: " + inputStream.readDouble());
            else if (type == ObsSerializer.TYPE_DATE)
                System.out.println("Value: " + inputStream.readUTF());
            System.out.println("Time: " + inputStream.readUTF());
            System.out.println("Obs: " + j + " out of: " + obsCounter);
        }
        Integer formCounter = inputStream.readInt();
        System.out.println("Form Counter: " + formCounter);
        for (int j = 0; j < formCounter; j++) {
            System.out.println("==================Observation=================");
            System.out.println("Patient Id: " + inputStream.readInt());
            System.out.println("Concept Name: " + inputStream.readUTF());

            byte type = inputStream.readByte();
            if (type == ObsSerializer.TYPE_STRING)
                System.out.println("Value: " + inputStream.readUTF());
            else if (type == ObsSerializer.TYPE_INT)
                System.out.println("Value: " + inputStream.readInt());
            else if (type == ObsSerializer.TYPE_DOUBLE)
                System.out.println("Value: " + inputStream.readDouble());
            else if (type == ObsSerializer.TYPE_DATE)
                System.out.println("Value: " + inputStream.readUTF());
            System.out.println("Time: " + inputStream.readUTF());
            System.out.println("Form: " + j + " out of: " + formCounter);
        }
    }
    inputStream.close();
}

From source file:com.serenegiant.media.TLMediaEncoder.java

private void checkLastSequence() {
    if (DEBUG)/*from  w w w . j  av a 2s .c  om*/
        Log.v(TAG, "checkLastSequence:");
    int sequence = -1;
    MediaFormat configFormat = null;
    try {
        final DataInputStream in = openInputStream(mBaseDir, mType, 0);
        if (in != null)
            try {
                // read MediaFormat data for MediaCodec and for MediaMuxer
                readHeader(in);
                configFormat = asMediaFormat(in.readUTF()); // for MediaCodec
                in.readUTF(); // for MediaMuxer
                // search last sequence
                // this is not a effective implementation for large intermediate file.
                // ex. it may be better to split into multiple files for each sequence
                // or split into two files; file for control block and file for raw bit stream.
                final TLMediaFrameHeader header = new TLMediaFrameHeader();
                for (; mIsRunning;) {
                    readHeader(in, header);
                    in.skipBytes(header.size);
                    sequence = Math.max(sequence, header.sequence);
                }
            } finally {
                in.close();
            }
    } catch (Exception e) {
        // ignore
    }
    mSequence = sequence;
    mConfigFormat = configFormat;
    if (sequence < 0) {
        // if intermediate files do not exist or invalid, remove them and re-create intermediate directory
        delete(mBaseDir);
        mBaseDir.mkdirs();
    }
    if (DEBUG)
        Log.v(TAG, "checkLastSequence:finished. sequence=" + sequence);
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Deserializes a <code>NodePropBundle</code> from a data input stream.
 *
 * @param in the input stream/*from   w  w  w  .  j  av a2  s.  com*/
 * @param id the node id for the new bundle
 * @return the bundle
 * @throws IOException if an I/O error occurs.
 */
public NodePropBundle readBundle(DataInputStream in, NodeId id) throws IOException {

    NodePropBundle bundle = new NodePropBundle(this, id);

    // read version and primary type...special handling
    int index = in.readInt();

    // get version
    int version = (index >> 24) & 0xff;
    index &= 0x00ffffff;
    String uri = nsIndex.indexToString(index);
    String local = nameIndex.indexToString(in.readInt());
    Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local);

    // primaryType
    bundle.setNodeTypeName(nodeTypeName);

    // parentUUID
    bundle.setParentId(readID(in));

    // definitionId
    bundle.setNodeDefId(NodeDefId.valueOf(in.readUTF()));

    // mixin types
    Set<Name> mixinTypeNames = new HashSet<Name>();
    Name name = readIndexedQName(in);
    while (name != null) {
        mixinTypeNames.add(name);
        name = readIndexedQName(in);
    }
    bundle.setMixinTypeNames(mixinTypeNames);

    // properties
    name = readIndexedQName(in);
    while (name != null) {
        PropertyId pId = new PropertyId(bundle.getId(), name);
        // skip redundant primaryType, mixinTypes and uuid properties
        if (name.equals(NameConstants.JCR_PRIMARYTYPE) || name.equals(NameConstants.JCR_MIXINTYPES)
                || name.equals(NameConstants.JCR_UUID)) {
            readPropertyEntry(in, pId);
            name = readIndexedQName(in);
            continue;
        }
        NodePropBundle.PropertyEntry pState = readPropertyEntry(in, pId);
        bundle.addProperty(pState);
        name = readIndexedQName(in);
    }

    // set referenceable flag
    bundle.setReferenceable(in.readBoolean());

    // child nodes (list of uuid/name pairs)
    NodeId childId = readID(in);
    while (childId != null) {
        bundle.addChildNodeEntry(readQName(in), childId);
        childId = readID(in);
    }

    // read modcount, since version 1.0
    if (version >= VERSION_1) {
        bundle.setModCount(readModCount(in));
    }

    // read shared set, since version 2.0
    Set<NodeId> sharedSet = new HashSet<NodeId>();
    if (version >= VERSION_2) {
        // shared set (list of parent uuids)
        NodeId parentId = readID(in);
        while (parentId != null) {
            sharedSet.add(parentId);
            parentId = readID(in);
        }
    }
    bundle.setSharedSet(sharedSet);

    return bundle;
}

From source file:VASSAL.launch.TilingHandler.java

protected void runSlicer(List<String> multi, final int tcount, int maxheap)
        throws CancellationException, IOException {

    final InetAddress lo = InetAddress.getByName(null);
    final ServerSocket ssock = new ServerSocket(0, 0, lo);

    final int port = ssock.getLocalPort();

    final List<String> args = new ArrayList<String>();
    args.addAll(Arrays.asList(new String[] { Info.javaBinPath, "-classpath",
            System.getProperty("java.class.path"), "-Xmx" + maxheap + "M", "-DVASSAL.id=" + pid,
            "-Duser.home=" + System.getProperty("user.home"), "-DVASSAL.port=" + port,
            "VASSAL.tools.image.tilecache.ZipFileImageTiler", aname, cdir.getAbsolutePath(),
            String.valueOf(tdim.width), String.valueOf(tdim.height) }));

    // get the progress dialog
    final ProgressDialog pd = ProgressDialog.createOnEDT(ModuleManagerWindow.getInstance(),
            "Processing Image Tiles", " ");

    // set up the process
    final InputStreamPump outP = new InputOutputStreamPump(null, System.out);
    final InputStreamPump errP = new InputOutputStreamPump(null, System.err);

    final ProcessWrapper proc = new ProcessLauncher().launch(null, outP, errP,
            args.toArray(new String[args.size()]));

    // write the image paths to child's stdin, one per line
    PrintWriter stdin = null;//from w  w w  .  j  av a2  s.  c  o  m
    try {
        stdin = new PrintWriter(proc.stdin);
        for (String m : multi) {
            stdin.println(m);
        }
    } finally {
        IOUtils.closeQuietly(stdin);
    }

    Socket csock = null;
    DataInputStream in = null;
    try {
        csock = ssock.accept();
        csock.shutdownOutput();

        in = new DataInputStream(csock.getInputStream());

        final Progressor progressor = new Progressor(0, tcount) {
            @Override
            protected void run(Pair<Integer, Integer> prog) {
                pd.setProgress((100 * prog.second) / max);
            }
        };

        // setup the cancel button in the progress dialog
        EDT.execute(new Runnable() {
            public void run() {
                pd.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        pd.setVisible(false);
                        proc.future.cancel(true);
                    }
                });
            }
        });

        boolean done = false;
        byte type;
        while (!done) {
            type = in.readByte();

            switch (type) {
            case STARTING_IMAGE:
                final String ipath = in.readUTF();

                EDT.execute(new Runnable() {
                    public void run() {
                        pd.setLabel("Tiling " + ipath);
                        if (!pd.isVisible())
                            pd.setVisible(true);
                    }
                });
                break;

            case TILE_WRITTEN:
                progressor.increment();

                if (progressor.get() >= tcount) {
                    pd.setVisible(false);
                }
                break;

            case TILING_FINISHED:
                done = true;
                break;

            default:
                throw new IllegalStateException("bad type: " + type);
            }
        }

        in.close();
        csock.close();
        ssock.close();
    } catch (IOException e) {

    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(csock);
        IOUtils.closeQuietly(ssock);
    }

    // wait for the tiling process to end
    try {
        final int retval = proc.future.get();
        if (retval != 0) {
            throw new IOException("return value == " + retval);
        }
    } catch (ExecutionException e) {
        // should never happen
        throw new IllegalStateException(e);
    } catch (InterruptedException e) {
        // should never happen
        throw new IllegalStateException(e);
    }
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Checks a <code>PropertyState</code> from the data input stream.
 *
 * @param in the input stream/*from w  w  w . ja  v  a 2  s. c  om*/
 * @return <code>true</code> if the data is valid;
 *         <code>false</code> otherwise.
 */
public boolean checkPropertyState(DataInputStream in) {
    int type;
    try {
        type = in.readInt();
        short modCount = (short) ((type >> 16) | 0xffff);
        type &= 0xffff;
        log.debug("  PropertyType: " + PropertyType.nameFromValue(type));
        log.debug("  ModCount: " + modCount);
    } catch (IOException e) {
        log.error("Error while reading property type: " + e);
        return false;
    }
    try {
        boolean isMV = in.readBoolean();
        log.debug("  MultiValued: " + isMV);
    } catch (IOException e) {
        log.error("Error while reading multivalued: " + e);
        return false;
    }
    try {
        String defintionId = in.readUTF();
        log.debug("  DefinitionId: " + defintionId);
    } catch (IOException e) {
        log.error("Error while reading definition id: " + e);
        return false;
    }

    int count;
    try {
        count = in.readInt();
        log.debug("  num values: " + count);
    } catch (IOException e) {
        log.error("Error while reading number of values: " + e);
        return false;
    }
    for (int i = 0; i < count; i++) {
        switch (type) {
        case PropertyType.BINARY:
            int size;
            try {
                size = in.readInt();
                log.debug("  binary size: " + size);
            } catch (IOException e) {
                log.error("Error while reading size of binary: " + e);
                return false;
            }
            if (size == BINARY_IN_DATA_STORE) {
                try {
                    String s = in.readUTF();
                    // truncate log output
                    if (s.length() > 80) {
                        s = s.substring(80) + "...";
                    }
                    log.debug("  global data store id: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else if (size == BINARY_IN_BLOB_STORE) {
                try {
                    String s = in.readUTF();
                    log.debug("  blobid: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else {
                // short values into memory
                byte[] data = new byte[size];
                try {
                    in.readFully(data);
                    log.debug("  binary: " + data.length + " bytes");
                } catch (IOException e) {
                    log.error("Error while reading inlined binary: " + e);
                    return false;
                }
            }
            break;
        case PropertyType.DOUBLE:
            try {
                double d = in.readDouble();
                log.debug("  double: " + d);
            } catch (IOException e) {
                log.error("Error while reading double value: " + e);
                return false;
            }
            break;
        case PropertyType.LONG:
            try {
                double l = in.readLong();
                log.debug("  long: " + l);
            } catch (IOException e) {
                log.error("Error while reading long value: " + e);
                return false;
            }
            break;
        case PropertyType.BOOLEAN:
            try {
                boolean b = in.readBoolean();
                log.debug("  boolean: " + b);
            } catch (IOException e) {
                log.error("Error while reading boolean value: " + e);
                return false;
            }
            break;
        case PropertyType.NAME:
            try {
                Name name = readQName(in);
                log.debug("  name: " + name);
            } catch (IOException e) {
                log.error("Error while reading name value: " + e);
                return false;
            }
            break;
        case PropertyType.REFERENCE:
            try {
                UUID uuid = readUUID(in);
                log.debug("  reference: " + uuid);
            } catch (IOException e) {
                log.error("Error while reading reference value: " + e);
                return false;
            }
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // Strings are serialized as <length><byte[]>
            int len;
            try {
                len = in.readInt();
                log.debug("  size of string value: " + len);
            } catch (IOException e) {
                log.error("Error while reading size of string value: " + e);
                return false;
            }
            try {
                byte[] bytes = new byte[len];
                in.readFully(bytes);
                String s = new String(bytes, "UTF-8");
                // truncate log output
                if (s.length() > 80) {
                    s = s.substring(80) + "...";
                }
                log.debug("  string: " + s);
            } catch (IOException e) {
                log.error("Error while reading string value: " + e);
                return false;
            }
        }
    }
    return true;
}

From source file:com.trigger_context.Main_Service.java

public void senderSync(DataInputStream in, DataOutputStream out, String folder) {
    String tfolder = folder + (folder.charAt(folder.length() - 1) == '/' ? "" : "/");
    File f = new File(folder);
    File file[] = f.listFiles();/*from w w  w.j a  v a 2s  .  c  o m*/
    // noti(file.toString(),"");
    String md5 = null;
    HashMap<String, File> hm = new HashMap<String, File>();

    HashSet<String> A = new HashSet<String>();
    for (File element : file) {
        hm.put(md5 = calculateMD5(element), element);
        A.add(md5);
    }
    // noti(hm.toString(),"");
    int numB = 0;
    try {
        numB = in.readInt();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        noti("error reading 1st int in sendersync", "");
        e.printStackTrace();
    }
    HashSet<String> B = new HashSet<String>();
    for (int i = 0; i < numB; i++) {
        try {
            B.add(in.readUTF());
        } catch (IOException e1) {
            noti("error in readins md5", "");
            e1.printStackTrace();
        }
    }
    HashSet<String> aMb = new HashSet<String>(A);
    aMb.removeAll(B);
    int l1 = aMb.size();
    try {
        out.writeInt(l1);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        noti("error in writing 1st int", "");
        e.printStackTrace();
    }
    Iterator<String> itr = aMb.iterator();
    while (itr.hasNext()) {
        f = hm.get(itr.next());
        sendFile(out, f.getPath());
    }
    HashSet<String> bMa = new HashSet<String>(B);
    bMa.removeAll(A);
    int l2 = bMa.size();
    try {
        out.writeInt(l2);
    } catch (IOException e) {
        // TODO Auto-generated catch block
        noti("error in writing 2nd int", "");
        e.printStackTrace();
    }
    itr = bMa.iterator();
    while (itr.hasNext()) {
        md5 = itr.next();
        try {
            out.writeUTF(md5);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            noti("error in sending md5", "");
            e.printStackTrace();
        }
        recvFile(in, folder);
    }
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Checks a <code>PropertyState</code> from the data input stream.
 *
 * @param in the input stream//from  w  ww.  ja v a 2 s.  c o m
 * @return <code>true</code> if the data is valid;
 *         <code>false</code> otherwise.
 */
public boolean checkPropertyState(DataInputStream in) {
    int type;
    try {
        type = in.readInt();
        short modCount = (short) ((type >> 16) | 0xffff);
        type &= 0xffff;
        log.debug("  PropertyType: " + PropertyType.nameFromValue(type));
        log.debug("  ModCount: " + modCount);
    } catch (IOException e) {
        log.error("Error while reading property type: " + e);
        return false;
    }
    try {
        boolean isMV = in.readBoolean();
        log.debug("  MultiValued: " + isMV);
    } catch (IOException e) {
        log.error("Error while reading multivalued: " + e);
        return false;
    }
    try {
        String defintionId = in.readUTF();
        log.debug("  DefinitionId: " + defintionId);
    } catch (IOException e) {
        log.error("Error while reading definition id: " + e);
        return false;
    }

    int count;
    try {
        count = in.readInt();
        log.debug("  num values: " + count);
    } catch (IOException e) {
        log.error("Error while reading number of values: " + e);
        return false;
    }
    for (int i = 0; i < count; i++) {
        switch (type) {
        case PropertyType.BINARY:
            int size;
            try {
                size = in.readInt();
                log.debug("  binary size: " + size);
            } catch (IOException e) {
                log.error("Error while reading size of binary: " + e);
                return false;
            }
            if (size == BINARY_IN_DATA_STORE) {
                try {
                    String s = in.readUTF();
                    // truncate log output
                    if (s.length() > 80) {
                        s = s.substring(80) + "...";
                    }
                    log.debug("  global data store id: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else if (size == BINARY_IN_BLOB_STORE) {
                try {
                    String s = in.readUTF();
                    log.debug("  blobid: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else {
                // short values into memory
                byte[] data = new byte[size];
                try {
                    in.readFully(data);
                    log.debug("  binary: " + data.length + " bytes");
                } catch (IOException e) {
                    log.error("Error while reading inlined binary: " + e);
                    return false;
                }
            }
            break;
        case PropertyType.DOUBLE:
            try {
                double d = in.readDouble();
                log.debug("  double: " + d);
            } catch (IOException e) {
                log.error("Error while reading double value: " + e);
                return false;
            }
            break;
        case PropertyType.DECIMAL:
            try {
                BigDecimal d = readDecimal(in);
                log.debug("  decimal: " + d);
            } catch (IOException e) {
                log.error("Error while reading decimal value: " + e);
                return false;
            }
            break;
        case PropertyType.LONG:
            try {
                double l = in.readLong();
                log.debug("  long: " + l);
            } catch (IOException e) {
                log.error("Error while reading long value: " + e);
                return false;
            }
            break;
        case PropertyType.BOOLEAN:
            try {
                boolean b = in.readBoolean();
                log.debug("  boolean: " + b);
            } catch (IOException e) {
                log.error("Error while reading boolean value: " + e);
                return false;
            }
            break;
        case PropertyType.NAME:
            try {
                Name name = readQName(in);
                log.debug("  name: " + name);
            } catch (IOException e) {
                log.error("Error while reading name value: " + e);
                return false;
            }
            break;
        case PropertyType.WEAKREFERENCE:
        case PropertyType.REFERENCE:
            try {
                NodeId id = readID(in);
                log.debug("  reference: " + id);
            } catch (IOException e) {
                log.error("Error while reading reference value: " + e);
                return false;
            }
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // Strings are serialized as <length><byte[]>
            int len;
            try {
                len = in.readInt();
                log.debug("  size of string value: " + len);
            } catch (IOException e) {
                log.error("Error while reading size of string value: " + e);
                return false;
            }
            try {
                byte[] bytes = new byte[len];
                in.readFully(bytes);
                String s = new String(bytes, "UTF-8");
                // truncate log output
                if (s.length() > 80) {
                    s = s.substring(80) + "...";
                }
                log.debug("  string: " + s);
            } catch (IOException e) {
                log.error("Error while reading string value: " + e);
                return false;
            }
        }
    }
    return true;
}

From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java

/**
 * Checks a <code>PropertyState</code> from the data input stream.
 *
 * @param in the input stream/*  w w  w.j  av  a 2 s  .c  om*/
 * @return <code>true</code> if the data is valid;
 *         <code>false</code> otherwise.
 */
public boolean checkPropertyState(DataInputStream in) {
    int type;
    try {
        type = in.readInt();
        short modCount = (short) ((type >> 16) | 0xffff);
        type &= 0xffff;
        log.debug("  PropertyType: " + PropertyType.nameFromValue(type));
        log.debug("  ModCount: " + modCount);
    } catch (IOException e) {
        log.error("Error while reading property type: " + e);
        return false;
    }
    try {
        boolean isMV = in.readBoolean();
        log.debug("  MultiValued: " + isMV);
    } catch (IOException e) {
        log.error("Error while reading multivalued: " + e);
        return false;
    }
    try {
        String defintionId = in.readUTF();
        log.debug("  DefinitionId: " + defintionId);
    } catch (IOException e) {
        log.error("Error while reading definition id: " + e);
        return false;
    }

    int count;
    try {
        count = in.readInt();
        log.debug("  num values: " + count);
    } catch (IOException e) {
        log.error("Error while reading number of values: " + e);
        return false;
    }
    for (int i = 0; i < count; i++) {
        switch (type) {
        case PropertyType.BINARY:
            int size;
            try {
                size = in.readInt();
                log.debug("  binary size: " + size);
            } catch (IOException e) {
                log.error("Error while reading size of binary: " + e);
                return false;
            }
            if (size == BINARY_IN_DATA_STORE) {
                try {
                    String s = in.readUTF();
                    // truncate log output
                    if (s.length() > 80) {
                        s = s.substring(80) + "...";
                    }
                    log.debug("  global data store id: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else if (size == BINARY_IN_BLOB_STORE) {
                try {
                    String s = in.readUTF();
                    log.debug("  blobid: " + s);
                } catch (IOException e) {
                    log.error("Error while reading blob id: " + e);
                    return false;
                }
            } else {
                // short values into memory
                byte[] data = new byte[size];
                try {
                    in.readFully(data);
                    log.debug("  binary: " + data.length + " bytes");
                } catch (IOException e) {
                    log.error("Error while reading inlined binary: " + e);
                    return false;
                }
            }
            break;
        case PropertyType.DOUBLE:
            try {
                double d = in.readDouble();
                log.debug("  double: " + d);
            } catch (IOException e) {
                log.error("Error while reading double value: " + e);
                return false;
            }
            break;
        case PropertyType.DECIMAL:
            try {
                BigDecimal d = readDecimal(in);
                log.debug("  decimal: " + d);
            } catch (IOException e) {
                log.error("Error while reading decimal value: " + e);
                return false;
            }
            break;
        case PropertyType.LONG:
            try {
                double l = in.readLong();
                log.debug("  long: " + l);
            } catch (IOException e) {
                log.error("Error while reading long value: " + e);
                return false;
            }
            break;
        case PropertyType.BOOLEAN:
            try {
                boolean b = in.readBoolean();
                log.debug("  boolean: " + b);
            } catch (IOException e) {
                log.error("Error while reading boolean value: " + e);
                return false;
            }
            break;
        case PropertyType.NAME:
            try {
                Name name = readQName(in);
                log.debug("  name: " + name);
            } catch (IOException e) {
                log.error("Error while reading name value: " + e);
                return false;
            }
            break;
        case PropertyType.WEAKREFERENCE:
        case PropertyType.REFERENCE:
            try {
                UUID uuid = readUUID(in);
                log.debug("  reference: " + uuid);
            } catch (IOException e) {
                log.error("Error while reading reference value: " + e);
                return false;
            }
            break;
        default:
            // because writeUTF(String) has a size limit of 64k,
            // Strings are serialized as <length><byte[]>
            int len;
            try {
                len = in.readInt();
                log.debug("  size of string value: " + len);
            } catch (IOException e) {
                log.error("Error while reading size of string value: " + e);
                return false;
            }
            try {
                byte[] bytes = new byte[len];
                in.readFully(bytes);
                String s = new String(bytes, "UTF-8");
                // truncate log output
                if (s.length() > 80) {
                    s = s.substring(80) + "...";
                }
                log.debug("  string: " + s);
            } catch (IOException e) {
                log.error("Error while reading string value: " + e);
                return false;
            }
        }
    }
    return true;
}