Example usage for java.io ObjectOutputStream flush

List of usage examples for java.io ObjectOutputStream flush

Introduction

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

Prototype

public void flush() throws IOException 

Source Link

Document

Flushes the stream.

Usage

From source file:net.sf.maltcms.chromaui.charts.FastHeatMapPlot.java

/**
 * Provides serialization support./*from w ww  .  j av a 2 s  .  c  o m*/
 *
 * @param stream the output stream.
 *
 * @throws IOException if there is an I/O error.
 */
private void writeObject(ObjectOutputStream stream) throws IOException {
    stream.defaultWriteObject();
    SerialUtilities.writePaint(this.paint, stream);
    SerialUtilities.writeStroke(this.domainGridlineStroke, stream);
    SerialUtilities.writePaint(this.domainGridlinePaint, stream);
    SerialUtilities.writeStroke(this.rangeGridlineStroke, stream);
    SerialUtilities.writePaint(this.rangeGridlinePaint, stream);
    stream.writeObject(ImageIO.write(this.dataImage, "PNG", stream));
    stream.flush();
}

From source file:junk.gui.HazardDataSetCalcCondorApp.java

/**
 * sets up the connection with the servlet on the server (gravity.usc.edu)
 *///from   w w w . j  a v a 2s . c o  m
private void sendParametersToServlet(SitesInGriddedRegion regionSites,
        ScalarIntensityMeasureRelationshipAPI imr, String eqkRupForecastLocation) {

    try {
        if (D)
            System.out.println("starting to make connection with servlet");
        URL hazardMapServlet = new URL(SERVLET_URL);

        URLConnection servletConnection = hazardMapServlet.openConnection();
        if (D)
            System.out.println("connection established");

        // inform the connection that we will send output and accept input
        servletConnection.setDoInput(true);
        servletConnection.setDoOutput(true);

        // Don't use a cached version of URL connection.
        servletConnection.setUseCaches(false);
        servletConnection.setDefaultUseCaches(false);
        // Specify the content type that we will send binary data
        servletConnection.setRequestProperty("Content-Type", "application/octet-stream");

        ObjectOutputStream toServlet = new ObjectOutputStream(servletConnection.getOutputStream());

        //sending the object of the gridded region sites to the servlet
        toServlet.writeObject(regionSites);
        //sending the IMR object to the servlet
        toServlet.writeObject(imr);
        //sending the EQK forecast object to the servlet
        toServlet.writeObject(eqkRupForecastLocation);
        //send the X values in a arraylist
        ArrayList list = new ArrayList();
        for (int i = 0; i < function.getNum(); ++i)
            list.add(new String("" + function.getX(i)));
        toServlet.writeObject(list);
        // send the MAX DISTANCE
        toServlet.writeObject(maxDistance);

        //sending email address to the servlet
        toServlet.writeObject(emailText.getText());
        //sending the parameters info. to the servlet
        toServlet.writeObject(getParametersInfo());

        //sending the dataset id to the servlet
        toServlet.writeObject(datasetIdText.getText());

        toServlet.flush();
        toServlet.close();

        // Receive the datasetnumber from the servlet after it has received all the data
        ObjectInputStream fromServlet = new ObjectInputStream(servletConnection.getInputStream());
        String dataset = fromServlet.readObject().toString();
        JOptionPane.showMessageDialog(this, dataset);
        if (D)
            System.out.println("Receiving the Input from the Servlet:" + dataset);
        fromServlet.close();

    } catch (Exception e) {
        ExceptionWindow bugWindow = new ExceptionWindow(this, e, getParametersInfo());
        bugWindow.setVisible(true);
        bugWindow.pack();
    }
}

From source file:org.apache.catalina.cluster.session.DeltaManager.java

/**
 * Save any currently active sessions in the appropriate persistence
 * mechanism, if any.  If persistence is not supported, this method
 * returns without doing anything.//w w  w  . java 2  s .co  m
 *
 * @exception IOException if an input/output error occurs
 */
private byte[] doUnload() throws IOException {

    // Open an output stream to the specified pathname, if any
    ByteArrayOutputStream fos = null;
    ObjectOutputStream oos = null;
    try {
        fos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(new BufferedOutputStream(fos));
    } catch (IOException e) {
        log.error(sm.getString("standardManager.unloading.ioe", e), e);
        if (oos != null) {
            try {
                oos.close();
            } catch (IOException f) {
                ;
            }
            oos = null;
        }
        throw e;
    }

    // Write the number of active sessions, followed by the details
    ArrayList list = new ArrayList();
    synchronized (sessions) {
        try {
            oos.writeObject(new Integer(sessions.size()));
            Iterator elements = sessions.values().iterator();
            while (elements.hasNext()) {
                DeltaSession session = (DeltaSession) elements.next();
                list.add(session);
                session.writeObjectData(oos);
            }
            oos.flush();
            oos.close();
            oos = null;
        } catch (IOException e) {
            log.error(sm.getString("standardManager.unloading.ioe", e), e);
            if (oos != null) {
                try {
                    oos.close();
                } catch (IOException f) {
                    ;
                }
                oos = null;
            }
            throw e;
        }
    }

    // Flush and close the output stream
    return fos.toByteArray();
}

From source file:cx.fbn.nevernote.Global.java

public static Object deepCopy(Object oldObj) {
    ObjectOutputStream oos = null;
    ObjectInputStream ois = null;
    try {//from w  w w  . j  a  va2 s  .c  om
        ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A
        oos = new ObjectOutputStream(bos); // B
        // serialize and pass the object
        oos.writeObject(oldObj); // C
        oos.flush(); // D
        ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E
        ois = new ObjectInputStream(bin); // F
        // return the new object
        return ois.readObject(); // G
    } catch (Exception e) {
        Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);
    }
    try {
        oos.close();
        ois.close();
    } catch (IOException e) {
        Global.logger.log(logger.LOW, "Exception in ObjectCloner = " + e);
        e.printStackTrace();
    }

    return null;
}

From source file:gtu._work.mvn.MavenRepositoryUI.java

private void initGUI() {
    try {//from   w  w w  .  ja v  a 2s.  c o  m
        {
        }
        BorderLayout thisLayout = new BorderLayout();
        getContentPane().setLayout(thisLayout);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
        {
            jTabbedPane1 = new JTabbedPane();
            getContentPane().add(jTabbedPane1, BorderLayout.CENTER);
            {
                jPanel1 = new JPanel();
                BorderLayout jPanel1Layout = new BorderLayout();
                jPanel1.setLayout(jPanel1Layout);
                scanList = new JList();
                jTabbedPane1.addTab("repository", null, jPanel1, null);
                {
                    scanText = new JTextField();
                    jPanel1.add(scanText, BorderLayout.NORTH);
                }
                {
                    jScrollPane1 = new JScrollPane();
                    jPanel1.add(jScrollPane1, BorderLayout.CENTER);
                    {
                        ListModel scanListModel = new DefaultListModel();
                        jScrollPane1.setViewportView(scanList);
                        scanList.setModel(scanListModel);
                        scanList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                defaultJListClick(scanList, evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel4 = new JPanel();
                BorderLayout jPanel4Layout = new BorderLayout();
                jPanel4.setLayout(jPanel4Layout);
                jTabbedPane1.addTab("repository only jar", null, jPanel4, null);
                jPanel4.setPreferredSize(new java.awt.Dimension(520, 298));
                {
                    scanText2 = new JTextField();
                    jPanel4.add(scanText2, BorderLayout.NORTH);
                }
                {
                    jScrollPane3 = new JScrollPane();
                    jPanel4.add(jScrollPane3, BorderLayout.CENTER);
                    {
                        scanList2 = new JList();
                        jScrollPane3.setViewportView(scanList2);
                        ListModel scanList2Model = new DefaultListModel();
                        scanList2.setModel(scanList2Model);
                        scanList2.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                defaultJListClick(scanList2, evt);
                            }
                        });
                    }
                }
                {
                }
            }
            {
                jPanel2 = new JPanel();
                BorderLayout jPanel2Layout = new BorderLayout();
                jPanel2.setLayout(jPanel2Layout);
                jTabbedPane1.addTab("jar find", null, jPanel2, null);
                {
                    jarFindText = new JTextField();
                    jPanel2.add(jarFindText, BorderLayout.NORTH);
                }
                {
                    jScrollPane2 = new JScrollPane();
                    jPanel2.add(jScrollPane2, BorderLayout.CENTER);
                    {
                        ListModel jarFindListModel = new DefaultListModel();
                        jarFindList = new JList();
                        jScrollPane2.setViewportView(jarFindList);
                        jarFindList.setModel(jarFindListModel);
                        jarFindList.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                defaultJListClick(jarFindList, evt);
                            }
                        });
                    }
                }
                {
                    jarFindExecute = new JButton();
                    jPanel2.add(jarFindExecute, BorderLayout.SOUTH);
                    jarFindExecute.setText("find");
                    jarFindExecute.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            String searchtext = jarFindText.getText();
                            if (StringUtils.isEmpty(searchtext) || searchtext.length() < 2) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("", "error");
                                return;
                            }
                            try {
                                DefaultListModel model = new DefaultListModel();
                                jarFindList.setModel(model);

                                searchtext = searchtext.trim();
                                searchtext = searchtext.replace('/', '.');
                                searchtext = searchtext.replace('\\', '.');

                                if (jarfinder == null) {
                                    jarfinder = JarFinder.newInstance();
                                } else {
                                    jarfinder.clear();
                                }

                                jarfinder.pattern(searchtext);

                                DefaultListModel scanModel = (DefaultListModel) scanList.getModel();
                                PomFile pomFile = null;
                                for (int ii = 0; ii < scanModel.getSize(); ii++) {
                                    pomFile = (PomFile) scanModel.getElementAt(ii);
                                    if (pomFile.jarFile == null) {
                                        continue;
                                    }
                                    jarfinder.setDir(pomFile.jarFile);
                                    if (!jarfinder.execute().isEmpty()) {
                                        model.addElement(pomFile);
                                    }
                                    jarfinder.getMap().clear();
                                }
                            } catch (Exception ex) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog(ex.getMessage(), "error");
                                ex.printStackTrace();
                            }
                        }
                    });
                }
            }
            {
                jPanel5 = new JPanel();
                BorderLayout jPanel5Layout = new BorderLayout();
                jTabbedPane1.addTab("detail", null, jPanel5, null);
                jPanel5.setLayout(jPanel5Layout);
                {
                    jScrollPane4 = new JScrollPane();
                    jPanel5.add(jScrollPane4, BorderLayout.CENTER);
                    {
                        TableModel scanTableModel = new DefaultTableModel();
                        scanTable = new JTable();
                        BorderLayout scanTableLayout = new BorderLayout();
                        scanTable.setLayout(scanTableLayout);
                        jScrollPane4.setViewportView(scanTable);
                        scanTable.setModel(scanTableModel);
                        JTableUtil.defaultSetting(scanTable);

                        scanTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                tableMouseClicked(scanTable, 0, evt);
                            }
                        });
                    }
                }
            }
            {
                jPanel3 = new JPanel();
                jTabbedPane1.addTab("config", null, jPanel3, null);
                GroupLayout jPanel3Layout = new GroupLayout((JComponent) jPanel3);
                jPanel3.setLayout(jPanel3Layout);
                {
                    copyToDir = new JButton();
                    copyToDir.setText("set copy to dir");
                    copyToDir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                                    .getApproveSelectedFile();
                            if (file == null || !file.exists() || !file.isDirectory()) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("dir is not correct!, set default desktop", "error");
                                file = FileUtil.DESKTOP_DIR;
                            }
                            copyTo = file;
                            System.out.println("copyTo: " + copyTo);
                        }
                    });
                }
                {
                    resetM2Dir = new JButton();
                    resetM2Dir.setText("set .m2 dir");
                    resetM2Dir.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectDirectoryOnly().showOpenDialog()
                                    .getApproveSelectedFile();
                            if (file == null || !file.exists() || !file.isDirectory()) {
                                showErrorMsg();
                                repositoryDir = DEFAULT_REPOSITORY_DIR;
                                reloadRepositoryDir();
                                return;
                            }
                            File newRepository = new File(file, "repository");
                            File settings = new File(file, "settings.xml");
                            if (settings.exists() && settings.isFile() && newRepository.exists()
                                    && newRepository.isDirectory()) {
                                repositoryDir = newRepository;
                                reloadRepositoryDir();
                            } else {
                                showErrorMsg();
                            }
                        }

                        void showErrorMsg() {
                            JOptionPaneUtil.newInstance().iconErrorMessage()
                                    .showMessageDialog("dir is not correct!, set default .m2 dir", "error");
                        }
                    });
                }
                {
                    saveCurrentDataBtn = new JButton();
                    saveCurrentDataBtn.setText("save current data");
                    saveCurrentDataBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File cfgFile = new File(PropertiesUtil.getJarCurrentPath(MavenRepositoryUI.class),
                                    MavenRepositoryUI.class.getSimpleName() + "_" + DateFormatUtil
                                            .format(System.currentTimeMillis(), "yyyyMMdd_HHmmss") + ".cfg");
                            try {
                                ObjectOutputStream writer = new ObjectOutputStream(
                                        new FileOutputStream(cfgFile));
                                writer.writeObject(pomFileList);
                                writer.writeObject(pomFileJarList);
                                writer.writeObject(pomFileMap);
                                writer.flush();
                                writer.close();
                                JOptionPaneUtil.newInstance().iconInformationMessage()
                                        .showMessageDialog("save completed!\n" + cfgFile, "SUCCESS");
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                                ex.printStackTrace();
                            }
                        }
                    });
                }
                {
                    loadConfigDataBtn = new JButton();
                    loadConfigDataBtn.setText("load config data");
                    loadConfigDataBtn.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File cfgFile = JFileChooserUtil.newInstance().selectFileOnly()
                                    .addAcceptFile("cfg", ".cfg").showOpenDialog().getApproveSelectedFile();
                            if (cfgFile == null) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("file is not correct!", "ERROR");
                                return;
                            }
                            try {
                                ObjectInputStream reader = new ObjectInputStream(new FileInputStream(cfgFile));
                                pomFileList = (Set<PomFile>) reader.readObject();
                                pomFileJarList = (Set<PomFile>) reader.readObject();
                                pomFileMap = (Map<DependencyKey, PomFile>) reader.readObject();
                                reader.close();
                                resetUIStatus();
                                JOptionPaneUtil.newInstance().iconInformationMessage()
                                        .showMessageDialog("load completed!\n" + cfgFile, "SUCCESS");
                            } catch (Exception ex) {
                                JCommonUtil.handleException(ex);
                                ex.printStackTrace();
                            }
                        }
                    });

                }
                jPanel3Layout.setHorizontalGroup(jPanel3Layout.createSequentialGroup().addContainerGap(24, 24)
                        .addGroup(jPanel3Layout.createParallelGroup()
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(loadConfigDataBtn,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(saveCurrentDataBtn,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(copyToDir,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(resetM2Dir,
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE))
                                .addGroup(jPanel3Layout.createSequentialGroup().addComponent(getJButton1(),
                                        GroupLayout.PREFERRED_SIZE, 223, GroupLayout.PREFERRED_SIZE)))
                        .addContainerGap(281, Short.MAX_VALUE));
                jPanel3Layout.setVerticalGroup(jPanel3Layout.createSequentialGroup().addContainerGap(25, 25)
                        .addComponent(copyToDir, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
                        .addGap(22)
                        .addComponent(resetM2Dir, GroupLayout.PREFERRED_SIZE, 30, GroupLayout.PREFERRED_SIZE)
                        .addGap(24)
                        .addComponent(saveCurrentDataBtn, GroupLayout.PREFERRED_SIZE, 31,
                                GroupLayout.PREFERRED_SIZE)
                        .addGap(25)
                        .addComponent(loadConfigDataBtn, GroupLayout.PREFERRED_SIZE, 31,
                                GroupLayout.PREFERRED_SIZE)
                        .addGap(28)
                        .addComponent(getJButton1(), GroupLayout.PREFERRED_SIZE, 31, GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(34, Short.MAX_VALUE));
            }
            {
                jPanel6 = new JPanel();
                BorderLayout jPanel6Layout = new BorderLayout();
                jPanel6.setLayout(jPanel6Layout);
                jTabbedPane1.addTab("pom dency", null, jPanel6, null);
                {
                    openPom = new JButton();
                    jPanel6.add(openPom, BorderLayout.NORTH);
                    openPom.setText("open");
                    openPom.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent evt) {
                            File file = JFileChooserUtil.newInstance().selectFileAndDirectory()
                                    .showDialog("?pom,pom").getApproveSelectedFile();
                            if (file == null) {
                                JOptionPaneUtil.newInstance().iconErrorMessage()
                                        .showMessageDialog("file is not correct!!", "ERROR");
                                return;
                            }
                            List<File> pomList = new ArrayList<File>();
                            if (file.isFile()
                                    && (file.getName().endsWith(".xml") || file.getName().endsWith(".pom"))) {
                                pomList.add(file);
                            } else {
                                FileUtil.searchFileMatchs(file, "pom.xml", pomList);
                            }
                            Set<PomFile> poms = loadPomList(pomList);
                            resetUIStatus();

                            Map<DependencyKey, PomFile> map = new HashMap<DependencyKey, PomFile>();
                            Set<LoadPomListDependency.DependencyKey> errorSet = new HashSet<LoadPomListDependency.DependencyKey>();
                            for (PomFile p : poms) {
                                openPomFetchDependency(p.pom, map, errorSet);
                            }

                            PomFile pfile = null;
                            DefaultTableModel model = JTableUtil.createModel(true, "groupId", "artifactId",
                                    "jar", "pomFile");
                            for (DependencyKey key : map.keySet()) {
                                pfile = map.get(key);
                                model.addRow(new Object[] { pfile.pom.groupId, pfile.pom.artifactId,
                                        (pfile.jarFile == null ? "" : pfile.jarFile.getName()), pfile });
                            }
                            for (LoadPomListDependency.DependencyKey key : errorSet) {
                                model.addRow(new Object[] { key.groupId, key.artifactId, "ERROR" });
                            }
                            pomDenpendencyTable.setModel(model);
                        }
                    });
                }
                {
                    jScrollPane5 = new JScrollPane();
                    jPanel6.add(jScrollPane5, BorderLayout.CENTER);
                    {
                        TableModel pomDenpendencyTableModel = new DefaultTableModel();
                        pomDenpendencyTable = new JTable();
                        jScrollPane5.setViewportView(pomDenpendencyTable);
                        pomDenpendencyTable.setModel(pomDenpendencyTableModel);
                        pomDenpendencyTable.addMouseListener(new MouseAdapter() {
                            public void mouseClicked(MouseEvent evt) {
                                tableMouseClicked(pomDenpendencyTable, 3, evt);
                            }
                        });
                        JTableUtil.defaultSetting(pomDenpendencyTable);
                    }
                }
                {
                    jPanel7 = new JPanel();
                    FlowLayout jPanel7Layout = new FlowLayout();
                    jPanel7Layout.setAlignOnBaseline(true);
                    jPanel6.add(jPanel7, BorderLayout.SOUTH);
                    jPanel7.setLayout(jPanel7Layout);
                    jPanel7.setPreferredSize(new java.awt.Dimension(520, 36));
                    {
                        clipboardListJar = new JButton();
                        jPanel7.add(clipboardListJar);
                        clipboardListJar.setText("jar list to clipboard");
                        clipboardListJar.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                List<File> list = fetchPomDependencyTableJarList();
                                StringBuilder sb = new StringBuilder();
                                for (File f : list) {
                                    sb.append(f + "\n");
                                }
                                ClipboardUtil.getInstance().setContents(sb);
                                JOptionPaneUtil.newInstance().iconInformationMessage()
                                        .showMessageDialog("clipboard set ok!", "SUCCESS");
                            }
                        });
                    }
                    {
                        pomOutputJarDir = new JButton();
                        jPanel7.add(pomOutputJarDir);
                        pomOutputJarDir.setText("set output jar dir");
                        pomOutputJarDir.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                File file = JFileChooserUtil.newInstance().selectDirectoryOnly()
                                        .showDialog("?Jar").getApproveSelectedFile();
                                if (file == null) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("dir is not correct!!", "ERROR");
                                    return;
                                }
                                pomOutputJarDir_ = file;
                            }
                        });
                    }
                    {
                        exportListJar = new JButton();
                        jPanel7.add(exportListJar);
                        exportListJar.setText("export list jar");
                        exportListJar.setPreferredSize(new java.awt.Dimension(113, 24));
                        exportListJar.addActionListener(new ActionListener() {
                            public void actionPerformed(ActionEvent evt) {
                                List<File> list = fetchPomDependencyTableJarList();
                                if (pomOutputJarDir_ == null || !pomOutputJarDir_.exists()
                                        || !pomOutputJarDir_.isDirectory()) {
                                    JOptionPaneUtil.newInstance().iconErrorMessage()
                                            .showMessageDialog("output dir is not correct!!", "ERROR");
                                    return;
                                }
                                if (JOptionPaneUtil.ComfirmDialogResult.YES_OK_OPTION == JOptionPaneUtil
                                        .newInstance().confirmButtonYesNo().iconWaringMessage()
                                        .showConfirmDialog("are you sure copy list jar count:(" + list.size()
                                                + ") to\n" + pomOutputJarDir_, "WARN")) {
                                    StringBuilder sb = new StringBuilder();
                                    StringBuilder fsb = new StringBuilder();
                                    sb.append("total : " + list.size() + "\n");
                                    int ok = 0;
                                    int noOk = 0;
                                    for (File f : list) {
                                        try {
                                            FileUtil.copyFile(f, new File(pomOutputJarDir_, f.getName()));
                                            ok++;
                                        } catch (IOException e) {
                                            e.printStackTrace();
                                            noOk++;
                                            fsb.append(f + "\n");
                                        }
                                    }
                                    sb.append("success : " + ok + "\n");
                                    sb.append("failed : " + noOk + "\n");
                                    sb.append("Failed jar :\n");
                                    sb.append(fsb);

                                    JOptionPaneUtil.newInstance().iconErrorMessage().showMessageDialog(sb,
                                            "COPY RESULT");
                                }

                            }
                        });
                    }
                }
            }
        }
        this.setSize(541, 365);

        reloadRepositoryDir();
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.tdod.ether.taimpl.player.DefaultPlayer.java

/**
 * Saves the player./*from www  .  j a  v  a 2  s. c  om*/
 */
public void save() {
    try {
        if (_name == null) {
            return;
        }

        if (_room != null) {
            _roomVnumSave = _room.getRoomNumber();
        } else {
            _roomVnumSave = 1;
        }

        String filename = PropertiesManager.getInstance().getProperty(PropertiesManager.PLAYER_DIR) + _name;
        FileOutputStream fos = new FileOutputStream(filename);
        GZIPOutputStream gzos = new GZIPOutputStream(fos);
        ObjectOutputStream out = new ObjectOutputStream(gzos);
        out.writeObject(this);
        out.flush();
        out.close();
    } catch (IOException e) {
        println("A problem occurred saving your character.  Contact an admin.");
        _log.fatal(e);
    }
}

From source file:org.apache.openjpa.persistence.EntityManagerImpl.java

public void writeExternal(ObjectOutput out) throws IOException {
    try {/* w w  w .  jav a  2 s .  co m*/
        // this requires that only AbstractBrokerFactory-sourced
        // brokers can be serialized
        Object factoryKey = ((AbstractBrokerFactory) _broker.getBrokerFactory()).getPoolKey();
        out.writeObject(factoryKey);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream innerOut = new ObjectOutputStream(baos);
        _broker.getDelegate().putUserObject(JPAFacadeHelper.EM_KEY, null);
        innerOut.writeObject(_broker.getDelegate());
        innerOut.flush();
        out.writeObject(baos.toByteArray());
    } catch (RuntimeException re) {
        try {
            re = _ret.translate(re);
        } catch (Exception e) {
            // ignore
        }
        throw re;
    }
}

From source file:org.apache.axis2.wsdl.util.WSDLWrapperSaveImpl.java

/**
 * Saves the current WSDL definition object that this wrapper contains.
 * This method has a number of checks to determine how to proceed with
 * the saving of the WSDL definition object, so the caller should not
 * need to make checks on whether to save or not.
 * <P>/*from   w  w w . j av  a2  s.c o m*/
 * The caller is responsible for handling the wrapped WSDL
 * definition object, for example, deciding when to release
 * it or reload it.
 * 
 * @return True - if the save succeeded
 *         False - if the save failed
 */
private boolean save() {

    // if the wsdl definiton failed to serialize from a previous attempt
    // to save it, then don't try to save it
    if (safeToSerialize == false) {
        // exit quickly
        return false;
    }

    // at this point, we think it is safe to proceed with saving the 
    // wsdl definition

    // make sure there is a file to use for saving the wsdl definition
    if (savedDefinitionFile == null) {
        try {
            savedDefinitionFile = File.createTempFile("wsdlDef_", null);
            savedFilename = savedDefinitionFile.getName();
            log.debug(myClassName + ".save(): temp file = [" + savedFilename + "]");
        } catch (Exception ex) {
            log.debug(myClassName + ".save(): error creating temp file = [" + ex.getMessage() + "]");
            savedDefinitionFile = null;
            savedFilename = null;

            // can't save the wsdl definition at this time
            // might be able to do so later
            hasBeenSaved = false;
            return false;
        }
    }

    if (savedDefinitionFile != null) {

        // the File object exists, check to see if the wsdl definition has
        // been previously saved

        if (hasBeenSaved && !hasBeenUpdatedSinceSaving) {
            // no need to save because we saved it already
            // and there were no updates to the wsdl definition object
            // since the previous save
            return true;
        }

        // ---------------------------------------------------------
        // save to the file
        // ---------------------------------------------------------
        FileOutputStream outStream = null;
        ObjectOutputStream outObjStream = null;

        try {
            // setup an output stream to a physical file
            outStream = new FileOutputStream(savedDefinitionFile);

            // attach a stream capable of writing objects to the 
            // stream connected to the file
            outObjStream = new ObjectOutputStream(outStream);

            // try to save the wsdl object
            log.debug(myClassName + ".save(): saving the wsdl definition.....");
            outObjStream.writeObject(wsdlDefinition);

            // close out the streams
            outObjStream.flush();
            outObjStream.close();
            outStream.flush();
            outStream.close();

            hasBeenSaved = true;
            hasBeenUpdatedSinceSaving = false;

            log.debug(myClassName + ".save(): ....saved the wsdl definition.....");

            long filesize = savedDefinitionFile.length();
            log.debug(myClassName + ".save(): file size after save [" + filesize + "]   temp file = ["
                    + savedFilename + "]");

            log.debug(myClassName + ".save(): end - - - - - - - - - - - - - - - -");
            return true;

        } catch (Exception ex2) {

            // disable future tries at saving this WSDL definition object
            safeToSerialize = false;

            // indicate that the file cannot be used to restore from
            hasBeenSaved = false;

            log.debug(myClassName + ".save(): error with saving the wsdl definition = ["
                    + ex2.getClass().getName() + " : " + ex2.getMessage() + "]", ex2);

            if (savedDefinitionFile != null) {
                try {
                    savedDefinitionFile.delete();
                    savedDefinitionFile = null;
                    savedFilename = null;
                } catch (Exception e) {
                    // just absorb it
                }
            }

            if (outObjStream != null) {
                try {
                    outObjStream.close();
                } catch (Exception e) {
                    // just absorb it
                }
            }

            if (outStream != null) {
                try {
                    outStream.close();
                } catch (Exception e) {
                    // just absorb it
                }
            }

            log.debug(myClassName + ".save(): error exit - - - - - - - - - - - - - - - -");
            return false;
        }
    }

    return false;
}

From source file:com.mods.grx.settings.GrxSettingsActivity.java

private String do_backup(String backup_name) {
    Common.sp.edit().putBoolean(Common.S_CTRL_SYNC_NEEDED, true).commit();
    Common.sp.edit().putInt(Common.S_CTRL_APP_VER, app_version()).commit();
    boolean error = false;
    String serror = "";
    ObjectOutputStream oos = null;
    FileOutputStream fos;//from  w w  w. j a  v a  2 s  .c om
    File f = new File(
            Common.BackupsDir + File.separator + backup_name + "." + getString(R.string.gs_backup_ext));
    try {
        fos = new FileOutputStream(f);
        oos = new ObjectOutputStream(fos);
    } catch (Exception e) {
        serror = e.toString();
        error = true;
    }
    if (!error) {
        try {
            Map<String, ?> prefes = Common.sp.getAll();
            if (oos != null)
                oos.writeObject(prefes);
        } catch (Exception e) {
            error = true;
            serror = e.toString();
        }
    }
    if (!error) {
        try {
            if (oos != null) {
                oos.flush();
                oos.close();
            }
        } catch (Exception e) {
            error = true;
            serror = e.toString();
        }
    }

    String res;
    if (error)
        res = "Error: " + serror;
    else
        res = getString(R.string.gs_backup_ok) + " :  " + backup_name + "." + getString(R.string.gs_backup_ext);

    if (!error) {

        String ori_icons_dir = Common.IconsDir + File.separator;
        String dest_icons_dir = Common.BackupsDir + File.separator + backup_name + File.separator
                + getString(R.string.grx_ico_sub_dir) + File.separator;
        Utils.delete_files_or_create_folder(dest_icons_dir, ".png");
        Utils.copy_files(ori_icons_dir, dest_icons_dir, ".png");
        Utils.fix_foler_permissions(dest_icons_dir, ".png");
        Utils.delete_files_or_create_folder(dest_icons_dir, ".jpg");
        Utils.copy_files(ori_icons_dir, dest_icons_dir, ".jpg");
        Utils.fix_foler_permissions(dest_icons_dir, ".jpg");
    }

    return res;

}

From source file:de.prozesskraft.pradar.parts.PradarPartUi3.java

/**
 * asks for entities from the first pradar-server that responds
 * @return void/*w w  w . j  a  v a 2  s  .  c  o  m*/
 */
void loadData() {
    for (String portAtMachineAsString : this.pradar_server_port_at_hostname) {
        String[] port_and_machine = portAtMachineAsString.split("@");

        int portNumber = Integer.parseInt(port_and_machine[0]);
        String machineName = port_and_machine[1];
        log("info", "want to load data from pradar-server");
        log("info", "trying pradar-server " + portNumber + "@" + machineName);
        try {

            // socket einrichten und Out/Input-Streams setzen
            //            log("debug", "machineName="+machineName+" | portNumber="+portNumber);

            //            log("debug", "server objekt erstellen");
            Socket connectToServerSocket = new Socket(machineName, portNumber);
            connectToServerSocket.setSoTimeout(20000);

            //            log("debug", "outputStream erstellen");
            OutputStream streamToServer = connectToServerSocket.getOutputStream();

            //            log("debug", "outputStream  flushen");
            streamToServer.flush();

            //            log("debug", "objectOutputStream  erstellen");
            ObjectOutputStream objectToServer = new ObjectOutputStream(streamToServer);

            //            log("debug", "objectOutputStream  flushen");
            objectToServer.flush();

            // Objekte zum server uebertragen
            //            log("debug", "write: getallfromuser");
            objectToServer.writeObject("getallfromuser");
            objectToServer.writeObject(System.getProperty("user.name"));

            //            log("debug", "outputStream  flushen");
            streamToServer.flush();

            //            log("debug", "objectOutputStream  flushen");
            objectToServer.flush();

            // sende-object zerstoeren - wird nicht mehr gebraucht
            //            log("debug", "objectOutputStream schliessen");
            //            objectToServer.close();

            //            log("debug", "inputStream erstellen");
            InputStream streamFromServer = connectToServerSocket.getInputStream();

            //            log("debug", "objectInputStream  erstellen");
            ObjectInputStream objectFromServer = new ObjectInputStream(streamFromServer);

            // Antwort vom Server lesen - ein array aller Entities
            try {
                //               log("debug", "reading");
                Object serverAnswer = objectFromServer.readObject();
                //               log("debug", "reading done");

                // lese-object zerstoeren - wird nicht mehr gebraucht
                objectFromServer.close();
                //               log("debug", "objectFromServer closed");

                ArrayList<Object> serverAnswer2 = null;
                if (serverAnswer instanceof ArrayList) {
                    //                  log("debug", "serverAnswer is an ArrayList");
                    serverAnswer2 = (ArrayList<Object>) serverAnswer;
                }

                // alle existierenden entities loeschen
                this.entities_all.clear();

                // die neuen entities casten und in einem map unterbringen id->Entities erstellen um die children bei ihren parents einsortieren zu koennen
                Map<String, Entity> entities_all = new HashMap<String, Entity>();
                for (Object actObject : serverAnswer2) {
                    // 
                    if (actObject instanceof Entity) {
                        //                     log("debug", "item of ArrayList<Object> is an Entity  --->  adding to ArrayList<Entity>");
                        Entity newEntity = (Entity) actObject;
                        this.entities_all.add(newEntity);
                    }
                }

                //               log("debug", "reading done! closing ");
                objectFromServer.close();

                //               log("debug", "read finished");
            } catch (ClassNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

            // daten holen aus db
            log("info", "refreshing data...");
            connectToServerSocket.close();

        } catch (UnknownHostException e) {
            log("warn", "unknown host " + machineName);
            this.pradar_server_port_at_hostname = null;
        } catch (IOException e) {
            log("warn", "input / output problems at " + portNumber + "@" + machineName);
            e.printStackTrace();
        }

        this.refresh_last = Calendar.getInstance();
        this.refresh_next = Calendar.getInstance();
        this.refresh_next.add(13, this.refresh_interval);
    }
}