Example usage for java.io ObjectInputStream readUTF

List of usage examples for java.io ObjectInputStream readUTF

Introduction

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

Prototype

public String readUTF() throws IOException 

Source Link

Document

Reads a String in modified UTF-8 format.

Usage

From source file:org.seasar.mayaa.impl.engine.specification.SpecificationNodeImpl.java

private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
    in.defaultReadObject();/*from   w w w .  j ava  2 s.  c  o  m*/
    if (_delegateNodeTreeWalker != null) {
        _delegateNodeTreeWalker.setOwner(this);
    }
    // namespace
    String currentMappingInfo = in.readUTF();
    NamespaceImpl namespace = deserialize(currentMappingInfo);
    setDefaultNamespaceMapping(namespace.getDefaultNamespaceMapping());
    for (Iterator it = namespace.iteratePrefixMapping(false); it.hasNext();) {
        PrefixMapping mapping = (PrefixMapping) it.next();
        addPrefixMapping(mapping.getPrefix(), mapping.getNamespaceURI());
    }
    // parent namespace
    Object nscheck = in.readObject();
    if (nscheck instanceof NamespaceImpl) {
        setParentSpace((Namespace) nscheck);
    }
    findNodeResolver().nodeLoaded(this);
}

From source file:com.izforge.izpack.installer.multiunpacker.MultiVolumeUnpackerTest.java

/**
 * Verifies that there are multiple volumes of the expected size.
 *
 * @param dir                the directory to find the volumes in
 * @param resources          the resources used to determine the volume name and count
 * @param maxFirstVolumeSize the maximum size of the first volume
 * @param maxVolumeSize      the maximum volume size for subsequent volumes
 * @throws IOException for any I/O error
 *///  ww w  .ja v a  2  s . com
private void checkVolumes(File dir, Resources resources, long maxFirstVolumeSize, long maxVolumeSize)
        throws IOException {
    // get the volume information
    ObjectInputStream info = new ObjectInputStream(resources.getInputStream(MultiVolumeUnpacker.VOLUMES_INFO));
    int count = info.readInt();
    String name = info.readUTF();
    info.close();
    assertTrue(count >= 1);

    // verify the primary volume exists, with the expected size
    File volume = new File(dir, name);
    assertTrue(volume.exists());
    assertEquals(maxFirstVolumeSize, volume.length());

    // check the existence and size of the remaining volumes
    for (int i = 1; i < count; ++i) {
        volume = new File(dir, name + "." + i);
        assertTrue(volume.exists());
        if (i < count - 1) {
            // can't check the size of the last volume
            assertEquals(maxVolumeSize, volume.length());
        }
    }
}

From source file:org.apache.lens.driver.hive.TestRemoteHiveDriver.java

/**
 * Read context./*from   w  w w. j  av a2  s  .c  o  m*/
 *
 * @param bytes  the bytes
 * @param driver the driver
 * @return the query context
 * @throws IOException            Signals that an I/O exception has occurred.
 * @throws ClassNotFoundException the class not found exception
 */
private QueryContext readContext(byte[] bytes, LensDriver driver) throws IOException, ClassNotFoundException {
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    ObjectInputStream in = new ObjectInputStream(bais);
    QueryContext ctx;
    try {
        ctx = (QueryContext) in.readObject();
        ctx.setConf(queryConf);
        boolean driverAvailable = in.readBoolean();
        if (driverAvailable) {
            String driverQualifiedName = in.readUTF();
            ctx.setSelectedDriver(driver);
        }
    } finally {
        in.close();
        bais.close();
    }
    return ctx;
}

From source file:org.interreg.docexplore.ServerConfigPanel.java

public ServerConfigPanel(final File config, final File serverDir) throws Exception {
    super(new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false));

    this.serverDir = serverDir;
    this.books = new Vector<Book>();
    this.bookList = new JList(new DefaultListModel());

    JPanel listPanel = new JPanel(new BorderLayout());
    listPanel.setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBooksLabel")));
    bookList.setOpaque(false);//from w  w  w  .  j  a  v  a2  s  . c o  m
    bookList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    bookList.setCellRenderer(new ListCellRenderer() {
        public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
                boolean cellHasFocus) {
            Book book = (Book) value;
            JLabel label = new JLabel("<html><b>" + book.name + "</b> - " + book.nPages + " pages</html>");
            label.setOpaque(true);
            if (isSelected) {
                label.setBackground(TextToolbar.styleHighLightedBackground);
                label.setForeground(Color.white);
            }
            if (book.deleted)
                label.setForeground(Color.red);
            else if (!book.used)
                label.setForeground(Color.gray);
            return label;
        }
    });
    bookList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting())
                return;
            setFields((Book) bookList.getSelectedValue());
        }
    });
    JScrollPane scrollPane = new JScrollPane(bookList, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(500, 300));
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    listPanel.add(scrollPane, BorderLayout.CENTER);

    JPanel importPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    importPanel.add(new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgImportLabel")) {
        public void actionPerformed(ActionEvent e) {
            final File inFile = DocExploreTool.getFileDialogs().openFile(DocExploreTool.getIBookCategory());
            if (inFile == null)
                return;

            try {
                final File tmpDir = new File(serverDir, "tmp");
                tmpDir.mkdir();

                GuiUtils.blockUntilComplete(new ProgressRunnable() {
                    float[] progress = { 0 };

                    public void run() {
                        try {
                            ZipUtils.unzip(inFile, tmpDir, progress);
                        } catch (Exception ex) {
                            ErrorHandler.defaultHandler.submit(ex);
                        }
                    }

                    public float getProgress() {
                        return (float) progress[0];
                    }
                }, ServerConfigPanel.this);

                File tmpFile = new File(tmpDir, "index.tmp");
                ObjectInputStream input = new ObjectInputStream(new FileInputStream(tmpFile));
                String bookFile = input.readUTF();
                String bookName = input.readUTF();
                String bookDesc = input.readUTF();
                input.close();

                new PresentationImporter().doImport(ServerConfigPanel.this, bookName, bookDesc,
                        new File(tmpDir, bookFile));
                FileUtils.cleanDirectory(tmpDir);
                FileUtils.deleteDirectory(tmpDir);
                updateBooks();
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
        }
    }));
    listPanel.add(importPanel, BorderLayout.SOUTH);
    add(listPanel);

    JPanel setupPanel = new JPanel(
            new LooseGridLayout(0, 1, 5, 5, true, false, SwingConstants.LEFT, SwingConstants.TOP, true, false));
    setupPanel.setBorder(
            BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgBookInfoLabel")));
    usedBox = new JCheckBox(XMLResourceBundle.getBundledString("cfgUseLabel"));
    usedBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book != null) {
                book.used = usedBox.isSelected();
                bookList.repaint();
            }
        }
    });
    setupPanel.add(usedBox);

    JPanel fieldPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT,
            SwingConstants.TOP, true, false));
    fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTitleLabel")));
    nameField = new JTextField(50);
    nameField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void changedUpdate(DocumentEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.name = nameField.getText();
            bookList.repaint();
        }
    });
    fieldPanel.add(nameField);

    fieldPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgDescriptionLabel")));
    descField = new JTextPane();
    //descField.setWrapStyleWord(true);
    descField.getDocument().addDocumentListener(new DocumentListener() {
        public void removeUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void insertUpdate(DocumentEvent e) {
            changedUpdate(e);
        }

        public void changedUpdate(DocumentEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.desc = descField.getText();
        }
    });
    scrollPane = new JScrollPane(descField, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    scrollPane.setPreferredSize(new Dimension(420, 50));
    scrollPane.getVerticalScrollBar().setUnitIncrement(10);
    fieldPanel.add(scrollPane);

    setupPanel.add(fieldPanel);

    exportButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgExportLabel")) {
        public void actionPerformed(ActionEvent e) {
            File file = DocExploreTool.getFileDialogs().saveFile(DocExploreTool.getIBookCategory());
            if (file == null)
                return;
            final Book book = (Book) bookList.getSelectedValue();
            final File indexFile = new File(serverDir, "index.tmp");
            try {
                final File outFile = file;
                ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(indexFile));
                out.writeUTF(book.bookFile.getName());
                out.writeUTF(book.name);
                out.writeUTF(book.desc);
                out.close();

                GuiUtils.blockUntilComplete(new ProgressRunnable() {
                    float[] progress = { 0 };

                    public void run() {
                        try {
                            ZipUtils.zip(serverDir, new File[] { indexFile, book.bookFile, book.bookDir },
                                    outFile, progress, 0, 1, 9);
                        } catch (Exception ex) {
                            ErrorHandler.defaultHandler.submit(ex);
                        }
                    }

                    public float getProgress() {
                        return (float) progress[0];
                    }
                }, ServerConfigPanel.this);
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
            if (indexFile.exists())
                indexFile.delete();
        }
    });
    deleteButton = new JButton(new AbstractAction(XMLResourceBundle.getBundledString("cfgDeleteRestoreLabel")) {
        public void actionPerformed(ActionEvent e) {
            Book book = (Book) bookList.getSelectedValue();
            if (book == null)
                return;
            book.deleted = !book.deleted;
            bookList.repaint();
        }
    });

    JPanel actionsPanel = new JPanel(new FlowLayout(FlowLayout.CENTER));
    actionsPanel.add(exportButton);
    actionsPanel.add(deleteButton);
    setupPanel.add(actionsPanel);

    add(setupPanel);

    JPanel optionsPanel = new JPanel(new LooseGridLayout(0, 2, 5, 5, false, false, SwingConstants.LEFT,
            SwingConstants.TOP, true, false));
    optionsPanel
            .setBorder(BorderFactory.createTitledBorder(XMLResourceBundle.getBundledString("cfgOptionsLabel")));
    JPanel timeoutPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    timeoutField = new JTextField(5);
    timeoutPanel.add(timeoutField);
    timeoutPanel.add(new JLabel(XMLResourceBundle.getBundledString("cfgTimeoutLabel")));
    optionsPanel.add(timeoutPanel);
    add(optionsPanel);

    updateBooks();
    setFields(null);

    final String xml = config.exists() ? StringUtils.readFile(config) : "<config></config>";
    String idle = StringUtils.getTagContent(xml, "idle");
    if (idle != null)
        try {
            timeoutField.setText("" + Integer.parseInt(idle));
        } catch (Throwable e) {
        }
}

From source file:bin.spider.frame.uri.CandidateURI.java

/**
 * Custom deserialization to reconstruct UURI instances from more
 * compact Strings. /*  w  ww.  j  a v a  2 s  .co m*/
 * 
 * @param stream
 * @throws IOException
 * @throws ClassNotFoundException
 */
private void readObject(ObjectInputStream stream) throws IOException, ClassNotFoundException {
    stream.defaultReadObject();
    uuri = readUuri(stream.readUTF());
    via = readUuri((String) stream.readObject());
    alist = (AList) stream.readObject();
}

From source file:org.kitesdk.data.spi.Constraints.java

/**
 * Reads in the {@link Constraints} from the provided {@code in} stream.
 * @param in the stream from which to deserialize the object.
 * @throws IOException error deserializing the {@link Constraints}
 * @throws ClassNotFoundException Unable to properly access values inside the {@link Constraints}
*///from  www . ja  va  2s.c o  m
private void readObject(java.io.ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();
    schema = new Parser().parse(in.readUTF());
    String json = in.readUTF();
    if (!json.isEmpty()) {
        strategy = PartitionStrategyParser.parse(json);
    }
    constraints = ImmutableMap.copyOf(ConstraintsSerialization.readConstraints(schema, strategy, in));
}

From source file:org.hibernate.internal.SessionFactoryImpl.java

/**
 * Custom deserialization hook used during Session deserialization.
 * //from   w  w w .ja v  a2 s . c  om
 * @param ois
 *            The stream from which to "read" the factory
 * @return The deserialized factory
 * @throws IOException
 *             indicates problems reading back serial data stream
 * @throws ClassNotFoundException
 *             indicates problems reading back serial data stream
 */
static SessionFactoryImpl deserialize(ObjectInputStream ois) throws IOException, ClassNotFoundException {
    LOG.trace("Deserializing SessionFactory from Session");
    final String uuid = ois.readUTF();
    boolean isNamed = ois.readBoolean();
    final String name = isNamed ? ois.readUTF() : null;
    return (SessionFactoryImpl) locateSessionFactoryOnDeserialization(uuid, name);
}

From source file:org.apache.hadoop.hive.ql.exec.spark.SparkDynamicPartitionPruner.java

private void processFiles(MapWork work, JobConf jobConf) throws HiveException {
    ObjectInputStream in = null;
    try {//from   w ww. ja va 2 s.  c o  m
        Path baseDir = work.getTmpPathForPartitionPruning();
        FileSystem fs = FileSystem.get(baseDir.toUri(), jobConf);

        // Find the SourceInfo to put values in.
        for (String name : sourceInfoMap.keySet()) {
            Path sourceDir = new Path(baseDir, name);
            for (FileStatus fstatus : fs.listStatus(sourceDir)) {
                LOG.info("Start processing pruning file: " + fstatus.getPath());
                in = new ObjectInputStream(fs.open(fstatus.getPath()));
                String columnName = in.readUTF();
                SourceInfo info = null;

                for (SourceInfo si : sourceInfoMap.get(name)) {
                    if (columnName.equals(si.columnName)) {
                        info = si;
                        break;
                    }
                }

                Preconditions.checkArgument(info != null,
                        "AssertionError: no source info for the column: " + columnName);

                // Read fields
                while (in.available() > 0) {
                    writable.readFields(in);

                    Object row = info.deserializer.deserialize(writable);
                    Object value = info.soi.getStructFieldData(row, info.field);
                    value = ObjectInspectorUtils.copyToStandardObject(value, info.fieldInspector);
                    info.values.add(value);
                }
            }
        }
    } catch (Exception e) {
        throw new HiveException(e);
    } finally {
        try {
            if (in != null) {
                in.close();
            }
        } catch (IOException e) {
            throw new HiveException("error while trying to close input stream", e);
        }
    }
}

From source file:idontwant2see.IDontWant2See.java

public void readData(final ObjectInputStream in) throws IOException, ClassNotFoundException {
    final int version = in.readInt(); // read Version

    int n = in.readInt();

    if (version <= 2) {
        for (int i = 0; i < n; i++) {
            final StringBuilder value = new StringBuilder("*");
            value.append(in.readUTF()).append("*");

            mSettings.getSearchList().add(new IDontWant2SeeListEntry(value.toString(), false));
        }//  ww  w . j a va2  s .c o m

        if (version == 2) {
            n = in.readInt();

            for (int i = 0; i < n; i++) {
                mSettings.getSearchList().add(new IDontWant2SeeListEntry(in.readUTF(), true));
            }

            mSettings.setSimpleMenu(false);
        }
    } else {
        for (int i = 0; i < n; i++) {
            mSettings.getSearchList().add(new IDontWant2SeeListEntry(in, version));
        }

        mSettings.setSimpleMenu(in.readBoolean());

        if (version >= 4) {
            mSettings.setSwitchToMyFilter(in.readBoolean());
        }
        if (version >= 5) {
            mSettings.setLastEnteredExclusionString(in.readUTF());
        }
        if (version >= 6) {
            mSettings.setLastUsedDate(Date.readData(in));
        }
        if (version >= 7) {
            mSettings.setProgramImportance(in.readByte());
        } else {
            mSettings.setProgramImportance(Program.DEFAULT_PROGRAM_IMPORTANCE);
        }
    }
}

From source file:org.taverna.server.master.localworker.RemoteRunDelegate.java

@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    in.defaultReadObject();//w w  w .  ja  v a2  s  . c  o  m
    if (log == null)
        log = getLog("Taverna.Server.LocalWorker");
    final String creatorName = in.readUTF();
    SecurityContextFactory factory = (SecurityContextFactory) in.readObject();
    try {
        secContext = factory.create(this, new UsernamePrincipal(creatorName));
    } catch (RuntimeException e) {
        throw e;
    } catch (IOException e) {
        throw e;
    } catch (Exception e) {
        throw new SecurityContextReconstructionException(e);
    }
    run = ((MarshalledObject<RemoteSingleRun>) in.readObject()).get();
}