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.googlecode.onevre.utils.ServerClassLoader.java

/**
 * Creates a new ServerClassLoader/*  www.  j a  v a 2  s. c  o m*/
 * @param parent The parent class loader
 * @param localCacheDirectory The directory to cache files to
 * @param remoteServer The URL of the remote server
 */
public ServerClassLoader(ClassLoader parent, File localCacheDirectory, URL remoteServer) {
    super(parent);
    this.localCacheDirectory = localCacheDirectory;
    this.localLibDirectory = new File(localCacheDirectory, LIB_DIR);
    File versionFile = new File(localCacheDirectory, "Version");
    boolean versionCorrect = false;
    if (!localCacheDirectory.exists()) {
        localCacheDirectory.mkdirs();
    } else {
        if (versionFile.exists()) {
            try {
                BufferedReader reader = new BufferedReader(new FileReader(versionFile));
                String version = reader.readLine();
                reader.close();
                versionCorrect = Defaults.PAG_VERSION.equals(version);
                log.info(version + " == " + Defaults.PAG_VERSION + " = " + versionCorrect);
            } catch (IOException e) {
                // Do Nothing
            }
        }
        try {
            FileInputStream input = new FileInputStream(new File(localCacheDirectory, INDEX));
            DataInputStream cacheFile = new DataInputStream(input);
            FileChannel channel = input.getChannel();
            while (channel.position() < channel.size()) {
                URL url = new URL(cacheFile.readUTF());
                String file = cacheFile.readUTF();
                if (versionCorrect && url.getHost().equals(remoteServer.getHost())
                        && (url.getPort() == remoteServer.getPort())) {
                    File jar = new File(localCacheDirectory, file);
                    if (jar.exists()) {
                        indexJar(url, jar);
                        CHECKED.put(url, true);
                    }
                }
            }
            input.close();
        } catch (FileNotFoundException e) {
            // Do Nothing - cache will be recreated later

        } catch (IOException e) {
            // Do Nothing - as above

        }
    }
    localLibDirectory.mkdirs();
    try {
        PrintWriter writer = new PrintWriter(versionFile);
        writer.println(Defaults.PAG_VERSION);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.remoteServer = remoteServer;
}

From source file:org.prorefactor.refactor.PUB.java

private void readHeader(DataInputStream in) throws IOException {
    unitClassName = in.readUTF();
    if (unitClassName.length() == 0)
        unitClassName = null;/*from   w w  w .j a  v  a  2 s . c om*/
    superClassName = in.readUTF();
    if (superClassName.length() == 0)
        superClassName = null;
}

From source file:ClassFileUtilities.java

/**
 * Returns the dependencies of the given class.
 * @return a list of strings representing the used classes.
 *///from   w w w.  j  a v a 2 s .c o  m
public static Set getClassDependencies(InputStream is) throws IOException {
    DataInputStream dis = new DataInputStream(is);

    if (dis.readInt() != 0xcafebabe) {
        throw new IOException("Invalid classfile");
    }

    dis.readInt();

    int len = dis.readShort();
    String[] strs = new String[len];
    Set classes = new HashSet();
    Set desc = new HashSet();

    for (int i = 1; i < len; i++) {
        int constCode = dis.readByte() & 0xff;
        switch (constCode) {
        case CONSTANT_LONG_INFO:
        case CONSTANT_DOUBLE_INFO:
            dis.readLong();
            i++;
            break;

        case CONSTANT_FIELDREF_INFO:
        case CONSTANT_METHODREF_INFO:
        case CONSTANT_INTERFACEMETHODREF_INFO:
        case CONSTANT_INTEGER_INFO:
        case CONSTANT_FLOAT_INFO:
            dis.readInt();
            break;

        case CONSTANT_CLASS_INFO:
            classes.add(new Integer(dis.readShort() & 0xffff));
            break;

        case CONSTANT_STRING_INFO:
            dis.readShort();
            break;

        case CONSTANT_NAMEANDTYPE_INFO:
            dis.readShort();
            desc.add(new Integer(dis.readShort() & 0xffff));
            break;

        case CONSTANT_UTF8_INFO:
            strs[i] = dis.readUTF();
            break;

        default:
            throw new RuntimeException("unexpected data in constant-pool:" + constCode);
        }
    }

    Set result = new HashSet();

    Iterator it = classes.iterator();
    while (it.hasNext()) {
        result.add(strs[((Integer) it.next()).intValue()]);
    }

    it = desc.iterator();
    while (it.hasNext()) {
        result.addAll(getDescriptorClasses(strs[((Integer) it.next()).intValue()]));
    }

    return result;
}

From source file:org.prorefactor.refactor.PUB.java

private void readSchema(DataInputStream in) throws IOException {
    for (;;) {/*from ww w. j a  v a 2  s . c om*/
        String tableName = in.readUTF();
        if (tableName.length() == 0)
            break;
        TableRef tableRef = new TableRef(tableName);
        tableMap.put(tableName.toLowerCase(), tableRef);
        for (;;) {
            String fieldName = in.readUTF();
            if (fieldName.length() == 0)
                break;
            tableRef.fieldMap.put(fieldName.toLowerCase(), fieldName);
        }
    }
}

From source file:org.prorefactor.refactor.PUB.java

private SymbolRef readSymbol(DataInputStream in) throws IOException {
    SymbolRef symbolRef = new SymbolRef(in.readInt(), in.readUTF());
    if (symbolRef.progressType == -1)
        return null;
    symbolRef.dataType = in.readInt();//www .j a  v a  2  s .  c  o m
    if (symbolRef.dataType == TokenTypes.CLASS)
        symbolRef.classSymbolRefName = in.readUTF();
    return symbolRef;
}

From source file:org.bdval.cache.TableCache.java

public ObjectSet<CharSequence> getTableColumnIds(final int splitId, final String splitType,
        final String datasetName) {
    final File cachedTableFile = getCachedTableFile(splitId, splitType, datasetName);
    final ObjectSet<CharSequence> result = new ObjectOpenHashSet<CharSequence>();
    DataInputStream dataInput = null;
    try {//from  w  w  w  .j a v a  2  s  .  com
        dataInput = new DataInputStream(new FastBufferedInputStream(new FileInputStream(cachedTableFile)));
        final int numberOfColumns = dataInput.readInt();
        LOG.info("Reading cached table with " + numberOfColumns + " columns");
        for (int i = 0; i < numberOfColumns; i++) {
            final String colType = dataInput.readUTF();
            final String colId = dataInput.readUTF();

            result.add(colId);

            if ("s".equals(colType)) {
                final int numStrings = dataInput.readInt();

                for (int j = 0; j < numStrings; j++) {
                    dataInput.readUTF();
                }
            } else if ("d".equals(colType)) {
                final int numDoubles = dataInput.readInt();
                // we don't need to read these doubles, just skip them;
                final int numBytes = Double.SIZE * numDoubles / 8;
                final int actualBytes = dataInput.skipBytes(numBytes);
                if (actualBytes != numBytes) {
                    LOG.warn("actual bytes skipped (" + actualBytes + ") does " + "not equal expected of "
                            + numBytes);
                }
            } else {
                LOG.error("UNKNOWN COLUMN TYPE " + colType + " cannot read cached table from file "
                        + filenameOf(cachedTableFile));
                return null;
            }
        }
        return result;
    } catch (IOException e) {
        LOG.error("Error getting column ids", e);
        return null;
    } finally {
        IOUtils.closeQuietly(dataInput);
    }
}

From source file:com.momock.http.HttpSession.java

void readHeaders() {
    try {/*from   ww w .j  av a 2  s .  co m*/
        if (!fileInfo.exists() || fileInfo.length() == 0)
            return;
        DataInputStream din = new DataInputStream(new FileInputStream(fileInfo));
        headers = new TreeMap<String, List<String>>();
        int headerCount = din.readInt();
        for (int i = 0; i < headerCount; i++) {
            String key = din.readUTF();
            int count = din.readInt();
            List<String> vals = new ArrayList<String>();
            for (int j = 0; j < count; j++) {
                String val = din.readUTF();
                vals.add(val);
            }
            headers.put(key, vals);
        }
        din.close();
    } catch (IOException e) {
        Logger.error(e);
    }
}

From source file:com.trigger_context.Main_Service.java

private void recvFile(DataInputStream in, String path) {
    Log.i("recvFile", "Start");
    // path should end with "/"
    String Filename = null;/*  ww  w  .  j av  a 2s .c om*/
    long size = 0;
    try {
        Filename = in.readUTF();
        size = in.readLong();
    } catch (IOException e1) {
        Log.i(Main_Service.LOG_TAG, "recvFile--error in readins file name and lngth");
    }

    OutputStream outfile = null;
    // noti("path of recv folder:",path);
    try {
        outfile = new FileOutputStream(path + Filename);
    } catch (FileNotFoundException e1) {
        Log.i(Main_Service.LOG_TAG, "recvFile--Error file not found exception");
    }

    byte[] buff = new byte[1024];
    int readbytes;
    try {
        while (size > 0 && (readbytes = in.read(buff, 0, (int) Math.min(buff.length, size))) != -1) {
            try {
                outfile.write(buff, 0, readbytes);
                size -= readbytes;
            } catch (IOException e) {
                Log.i(Main_Service.LOG_TAG, "recvFile--Error file write");
            }
        }
    } catch (IOException e) {
        Log.i(Main_Service.LOG_TAG, "recvFile--Error socket read");
        e.printStackTrace();
    }
    try {
        outfile.close();
    } catch (IOException e) {
        Log.i(Main_Service.LOG_TAG, "recvFile--Erro oufile close");
    }
}

From source file:org.apache.jackrabbit.core.persistence.mem.InMemBundlePersistenceManager.java

/**
 * Reads the content of the hash maps from the file system
 *
 * @throws Exception if an error occurs/*from   w  ww.  j a v a 2 s.  com*/
 */
public synchronized void loadContents() throws Exception {
    // read item states
    FileSystemResource fsRes = new FileSystemResource(wspFS, BUNDLE_FILE_PATH);
    if (!fsRes.exists()) {
        return;
    }
    BufferedInputStream bis = new BufferedInputStream(fsRes.getInputStream());
    DataInputStream in = new DataInputStream(bis);

    try {
        int n = in.readInt(); // number of entries
        while (n-- > 0) {
            String s = in.readUTF(); // id
            NodeId id = NodeId.valueOf(s);
            int length = in.readInt(); // data length
            byte[] data = new byte[length];
            in.readFully(data); // data
            // store in map
            bundleStore.put(id, data);
        }
    } finally {
        in.close();
    }

    // read references
    fsRes = new FileSystemResource(wspFS, REFS_FILE_PATH);
    bis = new BufferedInputStream(fsRes.getInputStream());
    in = new DataInputStream(bis);

    try {
        int n = in.readInt(); // number of entries
        while (n-- > 0) {
            String s = in.readUTF(); // target id
            NodeId id = NodeId.valueOf(s);
            int length = in.readInt(); // data length
            byte[] data = new byte[length];
            in.readFully(data); // data
            // store in map
            refsStore.put(id, data);
        }
    } finally {
        in.close();
    }

    if (!useFileBlobStore) {
        // read blobs
        fsRes = new FileSystemResource(wspFS, BLOBS_FILE_PATH);
        bis = new BufferedInputStream(fsRes.getInputStream());
        in = new DataInputStream(bis);

        try {
            int n = in.readInt(); // number of entries
            while (n-- > 0) {
                String id = in.readUTF(); // id
                int length = in.readInt(); // data length
                byte[] data = new byte[length];
                in.readFully(data); // data
                // store in map
                blobs.put(id, data);
            }
        } finally {
            in.close();
        }
    }
}

From source file:com.adito.notification.Notifier.java

void loadFromDisk() throws IOException {
    File[] f = queueDirectory.listFiles(new FileFilter() {
        public boolean accept(File f) {
            return f.getName().endsWith(".msg");
        }//from  w  w  w .ja  v  a 2s.c  o  m
    });
    // TODO better error handling in parsing of message files. Report on
    // non-existant / unreadable directory
    if (f == null) {
        throw new IOException("Could not list queue directory " + queueDirectory.getAbsolutePath());
    }
    for (int i = 0; i < f.length; i++) {
        FileInputStream fin = new FileInputStream(f[i]);
        try {
            DataInputStream din = new DataInputStream(fin);
            long id = din.readLong();
            String sinkName = din.readUTF();
            messageId = Math.max(id, messageId);
            boolean urgent = din.readBoolean();
            String subject = din.readUTF();
            List<Recipient> recipientList = new ArrayList<Recipient>();
            while (true) {
                int recipientType = din.readInt();
                if (recipientType == Recipient.EOF) {
                    break;
                } else {
                    String recipientAlias = din.readUTF();
                    String realmName = din.readUTF();
                    Recipient recipient = new Recipient(recipientType, recipientAlias, realmName);
                    recipientList.add(recipient);
                }
            }
            Properties parameters = new Properties();
            while (true) {
                int parameterType = din.readInt();
                if (parameterType < 1) {
                    break;
                } else {
                    String key = din.readUTF();
                    String val = din.readUTF();
                    parameters.setProperty(key, val);
                }
            }
            String content = din.readUTF();
            String lastMessage = din.readUTF();
            Message msg = new Message(subject, content, urgent);
            msg.setId(id);
            msg.setRecipients(recipientList);
            msg.setSinkName(sinkName);
            msg.setLastMessage(lastMessage);
            queue(msg);
        } finally {
            fin.close();
        }
    }
}