Example usage for java.io ObjectOutputStream writeUTF

List of usage examples for java.io ObjectOutputStream writeUTF

Introduction

In this page you can find the example usage for java.io ObjectOutputStream writeUTF.

Prototype

public void writeUTF(String str) throws IOException 

Source Link

Document

Primitive data write of this String in modified UTF-8 format.

Usage

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  va 2s  .com*/
    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:org.jbpm.console.ng.documents.backend.server.marshalling.CMISDocumentMarshallingStrategy.java

@Override
public byte[] marshal(Context context, ObjectOutputStream os, Object object) throws IOException {
    String path = "/";
    Document document = (Document) object;
    DocumentSummary summary = new DocumentSummary(document.getName(), "", path);
    summary.setContent(document.getContent());
    documentService.createDocument(summary);
    ByteArrayOutputStream buff = new ByteArrayOutputStream();
    ObjectOutputStream oos = new ObjectOutputStream(buff);
    oos.writeUTF(summary.getId());
    oos.writeUTF(document.getClass().getCanonicalName());
    String link = "http://localhost:8080/magnoliaAuthor/dms" + path + document.getName();
    oos.writeUTF(link);/*from   w w w.j a  v a  2s. co  m*/
    oos.close();
    return buff.toByteArray();
}

From source file:org.jbpm.integration.cmis.impl.OpenCMISPlaceholderResolverStrategy.java

public byte[] marshal(Context context, ObjectOutputStream os, Object object) throws IOException {
    Document document = (Document) object;
    Session session = getRepositorySession(user, password, url, repository);
    try {//from   w  w  w.j av  a  2 s  .  c om
        if (document.getContent() != null) {
            String type = getType(document);
            if (document.getIdentifier() == null || document.getIdentifier().isEmpty()) {
                String location = getLocation(document);

                Folder parent = findFolderForPath(session, location);
                if (parent == null) {
                    parent = createFolder(session, null, location);
                }
                org.apache.chemistry.opencmis.client.api.Document doc = createDocument(session, parent,
                        document.getName(), type, document.getContent());
                document.setIdentifier(doc.getId());
                document.addAttribute("updated", "true");
            } else {
                if (document.getContent() != null && "true".equals(document.getAttribute("updated"))) {
                    org.apache.chemistry.opencmis.client.api.Document doc = updateDocument(session,
                            document.getIdentifier(), type, document.getContent(), mode);

                    document.setIdentifier(doc.getId());
                    document.addAttribute("updated", "false");
                }
            }
        }
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(buff);
        oos.writeUTF(document.getIdentifier());
        oos.writeUTF(object.getClass().getCanonicalName());
        oos.close();
        return buff.toByteArray();
    } finally {
        session.clear();
    }
}

From source file:org.jbpm.integration.cmis.impl.OpenCMISPlaceholderResolverStrategy.java

public void write(ObjectOutputStream os, Object object) throws IOException {
    Document document = (Document) object;
    Session session = getRepositorySession(user, password, url, repository);
    try {/*from ww  w. ja  va2 s  .co  m*/
        if (document.getContent() != null) {
            String type = document.getAttribute("type");
            if (document.getIdentifier() == null) {
                String location = document.getAttribute("location");

                Folder parent = findFolderForPath(session, location);
                if (parent == null) {
                    parent = createFolder(session, null, location);
                }
                org.apache.chemistry.opencmis.client.api.Document doc = createDocument(session, parent,
                        document.getName(), type, document.getContent());
                document.setIdentifier(doc.getId());
                document.addAttribute("updated", "false");
            } else {
                if (document.getContent() != null && "true".equals(document.getAttribute("updated"))) {
                    org.apache.chemistry.opencmis.client.api.Document doc = updateDocument(session,
                            document.getIdentifier(), type, document.getContent(), mode);

                    document.setIdentifier(doc.getId());
                    document.addAttribute("updated", "false");
                }
            }
        }
        ByteArrayOutputStream buff = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(buff);
        oos.writeUTF(document.getIdentifier());
        oos.writeUTF(object.getClass().getCanonicalName());
        oos.close();
    } finally {
        session.clear();
    }
}

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

/**
 * Writes out the {@link Constraints} using Java serialization.
 *///w ww.  j  a  v a2 s  .c  om
private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();
    out.writeUTF(schema.toString());
    out.writeUTF(strategy != null ? strategy.toString() : "");
    ConstraintsSerialization.writeConstraints(schema, strategy, constraints, out);
}

From source file:org.mrgeo.hdfs.vector.shp.ShapefileReader.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.writeUTF(fileName);
    out.writeInt(source.ordinal());
}

From source file:org.seasar.mayaa.impl.engine.processor.TemplateProcessorSupport.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();//from w  w  w.  j  a va  2 s  .  c om
    String originalNodeID = NodeSerializeController.makeKey(_originalNode);
    String uniqueID = getUniqueID();
    out.writeUTF(originalNodeID);
    out.writeUTF(uniqueID);
    out.writeUTF(_injectedNode.getQName().getNamespaceURI().getValue());
    out.writeUTF(_injectedNode.getQName().getLocalName());

    NodeSerializeController controller = SpecificationImpl.nodeSerializer();
    if (controller.collectNode(_injectedNode)) {
        // ??
        out.writeUTF(UNIQUENESS_MARK);
        out.writeObject(_injectedNode);
    } else {
        // ???
        out.writeUTF(NodeSerializeController.makeKey(_injectedNode));
    }
    /*
    if (_injectedNode.getParentNode() != null && !(getParentProcessor() instanceof Template)) {
    String injectedNodeID = NodeSerializeController.makeKey(_injectedNode);
    out.writeUTF(injectedNodeID);
    } else {
    out.writeUTF(DUPLICATE_ROOT_MARK);
    out.writeObject(_injectedNode);
    }
      */
}

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

private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
    out.defaultWriteObject();/* w w  w  .  j a  va2 s.co m*/
    // namespace
    out.writeUTF(super.toString());
    if (getParentSpace() != null && getParentSpace().getClass() == NamespaceImpl.class) {
        out.writeObject(getParentSpace());
    } else {
        out.writeObject(new Serializable() {
            private static final long serialVersionUID = 1L;
        });
    }
}

From source file:org.spout.api.geo.discrete.Point.java

private void writeObject(java.io.ObjectOutputStream out) throws IOException {
    out.writeFloat(this.x);
    out.writeFloat(this.y);
    out.writeFloat(this.z);
    out.writeUTF(world != null ? world.getName() : "null");
}

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

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();//  w ww. ja va2s . c om
    out.writeUTF(secContext.getOwner().getName());
    out.writeObject(secContext.getFactory());
    out.writeObject(new MarshalledObject<RemoteSingleRun>(run));
}