List of usage examples for java.io BufferedWriter newLine
public void newLine() throws IOException
From source file:com.cloud.storage.resource.VmwareStorageProcessor.java
private void postCreatePrivateTemplate(String installFullPath, long templateId, String templateName, long size, long virtualSize) throws Exception { // TODO a bit ugly here BufferedWriter out = null; try {//from ww w . j a v a 2 s. co m out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(installFullPath + "/template.properties"), "UTF-8")); out.write("filename=" + templateName + ".ova"); out.newLine(); out.write("description="); out.newLine(); out.write("checksum="); out.newLine(); out.write("hvm=false"); out.newLine(); out.write("size=" + size); out.newLine(); out.write("ova=true"); out.newLine(); out.write("id=" + templateId); out.newLine(); out.write("public=false"); out.newLine(); out.write("ova.filename=" + templateName + ".ova"); out.newLine(); out.write("uniquename=" + templateName); out.newLine(); out.write("ova.virtualsize=" + virtualSize); out.newLine(); out.write("virtualsize=" + virtualSize); out.newLine(); out.write("ova.size=" + size); out.newLine(); } finally { if (out != null) { out.close(); } } }
From source file:com.cloud.storage.resource.VmwareStorageProcessor.java
private void writeMetaOvaForTemplate(String installFullPath, String ovfFilename, String vmdkFilename, String templateName, long diskSize) throws Exception { // TODO a bit ugly here BufferedWriter out = null; try {//w w w . j a va2 s. c o m out = new BufferedWriter(new OutputStreamWriter( new FileOutputStream(installFullPath + "/" + templateName + ".ova.meta"), "UTF-8")); out.write("ova.filename=" + templateName + ".ova"); out.newLine(); out.write("version=1.0"); out.newLine(); out.write("ovf=" + ovfFilename); out.newLine(); out.write("numDisks=1"); out.newLine(); out.write("disk1.name=" + vmdkFilename); out.newLine(); out.write("disk1.size=" + diskSize); out.newLine(); } finally { if (out != null) { out.close(); } } }
From source file:de.bfs.radon.omsimulation.gui.OMPanelResults.java
/** * Initialises the interface of the results panel. *///from w ww .ja va 2 s . com protected void initialize() { setLayout(null); lblExportChartTo = new JLabel("Export chart to ..."); lblExportChartTo.setBounds(436, 479, 144, 14); lblExportChartTo.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); lblExportChartTo.setVisible(false); add(lblExportChartTo); btnMaximize = new JButton("Fullscreen"); btnMaximize.setBounds(10, 475, 124, 23); btnMaximize.setFont(new Font("SansSerif", Font.PLAIN, 11)); btnMaximize.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (comboBoxSimulations.isEnabled()) { if (comboBoxSimulations.getSelectedItem() != null) { JFrame chartFrame = new JFrame(); OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem(); String title = simulation.toString(); DescriptiveStatistics statistics = null; OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem(); OMRoomType roomType = null; switch (statisticsType) { case RoomArithmeticMeans: title = "R_AM, " + title; statistics = simulation.getRoomAmDescriptiveStats(); roomType = OMRoomType.Room; break; case RoomGeometricMeans: title = "R_GM, " + title; statistics = simulation.getRoomGmDescriptiveStats(); roomType = OMRoomType.Room; break; case RoomMedianQ50: title = "R_MED, " + title; statistics = simulation.getRoomMedDescriptiveStats(); roomType = OMRoomType.Room; break; case RoomMaxima: title = "R_MAX, " + title; statistics = simulation.getRoomMaxDescriptiveStats(); roomType = OMRoomType.Room; break; case CellarArithmeticMeans: title = "C_AM, " + title; statistics = simulation.getCellarAmDescriptiveStats(); roomType = OMRoomType.Cellar; break; case CellarGeometricMeans: title = "C_GM, " + title; statistics = simulation.getCellarGmDescriptiveStats(); roomType = OMRoomType.Cellar; break; case CellarMedianQ50: title = "C_MED, " + title; statistics = simulation.getCellarMedDescriptiveStats(); roomType = OMRoomType.Cellar; break; case CellarMaxima: title = "C_MAX, " + title; statistics = simulation.getCellarMaxDescriptiveStats(); roomType = OMRoomType.Cellar; break; default: title = "R_AM, " + title; statistics = simulation.getRoomAmDescriptiveStats(); roomType = OMRoomType.Misc; break; } JPanel chartPanel = createDistributionPanel(title, statistics, roomType, false, true, true); chartFrame.getContentPane().add(chartPanel); chartFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); Dimension dim = Toolkit.getDefaultToolkit().getScreenSize(); chartFrame.setBounds(0, 0, (int) dim.getWidth(), (int) dim.getHeight()); chartFrame.setTitle("OM Simulation Tool: " + title); chartFrame.setResizable(true); chartFrame.setExtendedState(JFrame.MAXIMIZED_BOTH); chartFrame.setVisible(true); } } } }); add(btnMaximize); btnCsv = new JButton("CSV"); btnCsv.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.csv", "csv")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String csv; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("csv")) { csv = ""; } else { csv = ".csv"; } String csvPath = file.getAbsolutePath() + csv; OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem(); OMCampaign[] campaigns = simulation.getCampaigns(); File csvFile = new File(csvPath); try { FileWriter logWriter = new FileWriter(csvFile); BufferedWriter csvOutput = new BufferedWriter(logWriter); OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem(); String head = ""; switch (statisticsType) { case RoomArithmeticMeans: head = "R_AM"; break; case RoomGeometricMeans: head = "R_GM"; break; case RoomMedianQ50: head = "R_MED"; break; case RoomMaxima: head = "R_MAX"; break; case CellarArithmeticMeans: head = "C_AM"; break; case CellarGeometricMeans: head = "C_GM"; break; case CellarMedianQ50: head = "C_MED"; break; case CellarMaxima: head = "C_MAX"; break; default: head = "R_AM"; break; } csvOutput.write("\"ID\";\"CAMPAIGN\";\"START\";\"" + head + "\""); csvOutput.newLine(); int value = 0; for (int i = 0; i < campaigns.length; i++) { switch (statisticsType) { case RoomArithmeticMeans: value = (int) campaigns[i].getRoomAverage(); break; case RoomGeometricMeans: value = (int) campaigns[i].getRoomLogAverage(); break; case RoomMedianQ50: value = (int) campaigns[i].getRoomMedian(); break; case RoomMaxima: value = (int) campaigns[i].getRoomMaximum(); break; case CellarArithmeticMeans: value = (int) campaigns[i].getCellarAverage(); break; case CellarGeometricMeans: value = (int) campaigns[i].getCellarLogAverage(); break; case CellarMedianQ50: value = (int) campaigns[i].getCellarMedian(); break; case CellarMaxima: value = (int) campaigns[i].getCellarMaximum(); break; default: value = (int) campaigns[i].getRoomAverage(); break; } csvOutput.write("\"" + i + "\";\"" + campaigns[i].getVariation() + "\";\"" + campaigns[i].getStart() + "\";\"" + value + "\""); csvOutput.newLine(); } JOptionPane.showMessageDialog(null, "CSV saved successfully!\n" + csvPath, "Success", JOptionPane.INFORMATION_MESSAGE); csvOutput.close(); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write CSV. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnCsv.setBounds(590, 475, 70, 23); btnCsv.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnCsv.setVisible(false); add(btnCsv); btnPdf = new JButton("PDF"); btnPdf.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.pdf", "pdf")); fileDialog.showSaveDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String pdf; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("pdf")) { pdf = ""; } else { pdf = ".pdf"; } String pdfPath = file.getAbsolutePath() + pdf; OMSimulation simulation = (OMSimulation) comboBoxSimulations.getSelectedItem(); String title = simulation.toString(); DescriptiveStatistics statistics = null; OMStatistics statisticsType = (OMStatistics) comboBoxStatistics.getSelectedItem(); OMRoomType roomType = null; switch (statisticsType) { case RoomArithmeticMeans: title = "R_AM, " + title; statistics = simulation.getRoomAmDescriptiveStats(); roomType = OMRoomType.Room; break; case RoomGeometricMeans: title = "R_GM, " + title; statistics = simulation.getRoomGmDescriptiveStats(); roomType = OMRoomType.Room; break; case RoomMedianQ50: title = "R_MED, " + title; statistics = simulation.getRoomMedDescriptiveStats(); roomType = OMRoomType.Room; break; case RoomMaxima: title = "R_MAX, " + title; statistics = simulation.getRoomMaxDescriptiveStats(); roomType = OMRoomType.Room; break; case CellarArithmeticMeans: title = "C_AM, " + title; statistics = simulation.getCellarAmDescriptiveStats(); roomType = OMRoomType.Cellar; break; case CellarGeometricMeans: title = "C_GM, " + title; statistics = simulation.getCellarGmDescriptiveStats(); roomType = OMRoomType.Cellar; break; case CellarMedianQ50: title = "C_MED, " + title; statistics = simulation.getCellarMedDescriptiveStats(); roomType = OMRoomType.Cellar; break; case CellarMaxima: title = "C_MAX, " + title; statistics = simulation.getCellarMaxDescriptiveStats(); roomType = OMRoomType.Cellar; break; default: title = "R_AM, " + title; statistics = simulation.getRoomAmDescriptiveStats(); roomType = OMRoomType.Misc; break; } JFreeChart chart = OMCharts.createDistributionChart(title, statistics, roomType, false); int height = (int) PageSize.A4.getWidth(); int width = (int) PageSize.A4.getHeight(); try { OMExports.exportPdf(pdfPath, chart, width, height, new DefaultFontMapper(), title); JOptionPane.showMessageDialog(null, "PDF saved successfully!\n" + pdfPath, "Success", JOptionPane.INFORMATION_MESSAGE); } catch (IOException ioe) { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check permissions!\n" + ioe.getMessage(), "Failed", JOptionPane.ERROR_MESSAGE); ioe.printStackTrace(); } } else { JOptionPane.showMessageDialog(null, "Failed to write PDF. Please check the file path!", "Failed", JOptionPane.ERROR_MESSAGE); } } }); btnPdf.setBounds(670, 475, 70, 23); btnPdf.setFont(new Font(Font.SANS_SERIF, Font.PLAIN, 11)); btnPdf.setVisible(false); add(btnPdf); lblSelectSimulation = new JLabel("Select Simulation"); lblSelectSimulation.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblSelectSimulation.setBounds(10, 65, 132, 14); add(lblSelectSimulation); lblSelectStatistics = new JLabel("Select Statistics"); lblSelectStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblSelectStatistics.setBounds(10, 94, 132, 14); add(lblSelectStatistics); comboBoxSimulations = new JComboBox<OMSimulation>(); comboBoxSimulations.setFont(new Font("SansSerif", Font.PLAIN, 11)); comboBoxSimulations.addPropertyChangeListener(new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent arg0) { boolean b = false; if (comboBoxSimulations.isEnabled()) { if (comboBoxSimulations.getSelectedItem() != null) { b = true; comboBoxStatistics.removeAllItems(); comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values())); } else { b = false; comboBoxStatistics.removeAllItems(); } } else { b = false; comboBoxStatistics.removeAllItems(); } progressBar.setEnabled(b); btnPdf.setVisible(b); btnCsv.setVisible(b); btnMaximize.setVisible(b); lblExportChartTo.setVisible(b); comboBoxStatistics.setEnabled(b); lblSelectStatistics.setEnabled(b); } }); comboBoxSimulations.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { boolean b = false; if (comboBoxSimulations.isEnabled()) { if (comboBoxSimulations.getSelectedItem() != null) { b = true; comboBoxStatistics.removeAllItems(); comboBoxStatistics.setModel(new DefaultComboBoxModel<OMStatistics>(OMStatistics.values())); comboBoxStatistics.setSelectedIndex(0); } else { b = false; comboBoxStatistics.removeAllItems(); } } else { b = false; comboBoxStatistics.removeAllItems(); } progressBar.setEnabled(b); btnPdf.setVisible(b); btnCsv.setVisible(b); btnMaximize.setVisible(b); lblExportChartTo.setVisible(b); comboBoxStatistics.setEnabled(b); lblSelectStatistics.setEnabled(b); } }); comboBoxSimulations.setBounds(152, 61, 454, 22); add(comboBoxSimulations); btnRefresh = new JButton("Load"); btnRefresh.setFont(new Font("SansSerif", Font.PLAIN, 11)); btnRefresh.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { if (txtOmsFile.getText() != null && !txtOmsFile.getText().equals("") && !txtOmsFile.getText().equals(" ")) { txtOmsFile.setBackground(Color.WHITE); String omsPath = txtOmsFile.getText(); String oms; String[] tmpFileName = omsPath.split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("oms")) { oms = ""; } else { oms = ".oms"; } txtOmsFile.setText(omsPath + oms); setOmsFile(omsPath + oms); File omsFile = new File(omsPath + oms); if (omsFile.exists()) { txtOmsFile.setBackground(Color.WHITE); btnRefresh.setEnabled(false); comboBoxSimulations.setEnabled(false); setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); progressBar.setStringPainted(true); progressBar.setVisible(true); progressBar.setIndeterminate(true); btnPdf.setVisible(false); btnCsv.setVisible(false); btnMaximize.setVisible(false); lblExportChartTo.setVisible(false); refreshSimulationsTask = new RefreshSimulations(); refreshSimulationsTask.execute(); } else { txtOmsFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "OMS-file not found, please check the file path!", "Error", JOptionPane.ERROR_MESSAGE); } } else { txtOmsFile.setBackground(new Color(255, 222, 222, 128)); JOptionPane.showMessageDialog(null, "Please select an OMS-file!", "Warning", JOptionPane.WARNING_MESSAGE); } } }); comboBoxStatistics = new JComboBox<OMStatistics>(); comboBoxStatistics.setFont(new Font("SansSerif", Font.PLAIN, 11)); comboBoxStatistics.setBounds(152, 90, 454, 22); comboBoxStatistics.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { updateDistribution(); } }); add(comboBoxStatistics); btnRefresh.setBounds(616, 61, 124, 23); add(btnRefresh); panelDistribution = new JPanel(); panelDistribution.setBounds(10, 118, 730, 347); add(panelDistribution); progressBar = new JProgressBar(); progressBar.setFont(new Font("SansSerif", Font.PLAIN, 11)); progressBar.setBounds(10, 475, 730, 23); add(progressBar); progressBar.setEnabled(false); comboBoxStatistics.setEnabled(false); lblSelectStatistics.setEnabled(false); btnPdf.setVisible(false); btnCsv.setVisible(false); btnMaximize.setVisible(false); lblExportChartTo.setVisible(false); lblHelp = new JLabel("Select an OMS-Simulation file to analyse the simulation results and " + "display the distribution chart."); lblHelp.setForeground(Color.GRAY); lblHelp.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblHelp.setBounds(10, 10, 730, 14); add(lblHelp); lblSelectOms = new JLabel("Open OMS-File"); lblSelectOms.setFont(new Font("SansSerif", Font.PLAIN, 11)); lblSelectOms.setBounds(10, 36, 132, 14); add(lblSelectOms); txtOmsFile = new JTextField(); txtOmsFile.addFocusListener(new FocusAdapter() { @Override public void focusLost(FocusEvent e) { setOmsFile(txtOmsFile.getText()); } }); txtOmsFile.setFont(new Font("SansSerif", Font.PLAIN, 11)); txtOmsFile.setColumns(10); txtOmsFile.setBounds(152, 33, 454, 20); add(txtOmsFile); buttonBrowse = new JButton("Browse"); buttonBrowse.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { JFileChooser fileDialog = new JFileChooser(); fileDialog.setFileFilter(new FileNameExtensionFilter("*.oms", "oms")); fileDialog.showOpenDialog(getParent()); final File file = fileDialog.getSelectedFile(); if (file != null) { String oms; String[] tmpFileName = file.getAbsolutePath().split("\\."); if (tmpFileName[tmpFileName.length - 1].equals("oms")) { oms = ""; } else { oms = ".oms"; } txtOmsFile.setText(file.getAbsolutePath() + oms); setOmsFile(file.getAbsolutePath() + oms); } } }); buttonBrowse.setFont(new Font("SansSerif", Font.PLAIN, 11)); buttonBrowse.setBounds(616, 32, 124, 23); add(buttonBrowse); progressBar.setVisible(false); }
From source file:com.archivas.clienttools.arcutils.utils.database.ManagedJobSchema.java
private void outputResults(boolean includeErrMsg, Integer includeOnlyRowsWithStatusCode, FileStatus status, File outFile, AbstractProfileBase sourceProfile) throws IOException, SQLException { synchronized (DatabaseResourceManager.DB_LOCK) { PooledDbConnection conn = null;//from w w w .j a v a2 s .c o m FileWriter fstream = new FileWriter(outFile); BufferedWriter out = new BufferedWriter(fstream); try { conn = connPool.getConnection(); String sql = "SELECT " + ManagedJobFilesTableColumn.SOURCE_PATH.toString() + (includeErrMsg ? ", " + ManagedJobFilesTableColumn.EXCEPTION_MSG.toString() : "") + " FROM " + qualifiedFilesTableName + " WHERE " + ManagedJobFilesTableColumn.INCLUDE_IN_INVENTORY.toString() + " = 1"; if (status != null) { sql += " AND " + ManagedJobFilesTableColumn.STATUS.toString() + " = " + status.ordinal(); } if (includeOnlyRowsWithStatusCode != null) { sql += " AND " + ManagedJobFilesTableColumn.STATUS_CODE.toString() + " = " + includeOnlyRowsWithStatusCode; } Statement stmt = conn.createStatement(); long startTime = System.currentTimeMillis(); DB_PERFORMANCE_LOG.log(Level.FINE, "Executing export results query: " + sql); ResultSet rs = stmt.executeQuery(sql); DB_PERFORMANCE_LOG.log(Level.FINE, "Executed export results query in " + (System.currentTimeMillis() - startTime) + " ms"); long cnt = 0; while (rs.next()) { out.write( sourceProfile.decode(rs.getString(ManagedJobFilesTableColumn.SOURCE_PATH.toString()))); if (includeErrMsg) { out.write("," + rs.getString(ManagedJobFilesTableColumn.EXCEPTION_MSG.toString())); } out.newLine(); cnt++; } DB_PERFORMANCE_LOG.log(Level.FINE, "Exported " + cnt + " files in " + (System.currentTimeMillis() - startTime) + " ms"); } finally { connPool.returnConnection(conn); out.close(); } } }
From source file:com.zimbra.cs.util.ProxyConfOverride.java
/** * Enumerate all virtual host names and virtual ip addresses and * apply them into the var replacement.<br/> * explode domain command has this format:<br/> * <code>!{explode domain(arg1, arg2, ...)}</code><br/> * The args indicate the required attrs to generate a server block * , which now supports://from w ww. j av a 2s . c o m * <ul> * <li>vhn: zimbraVirtualHostname must not be empty</li> * <li>sso: zimbraClientCertMode must not be empty or "off"</li> * </ul> * @author Jiankuan * @throws ProxyConfException */ private static void expandTemplateByExplodeDomain(BufferedReader temp, BufferedWriter conf, String[] requiredAttrs) throws IOException, ProxyConfException { int size = mDomainReverseProxyAttrs.size(); List<String> cache = null; if (size > 0) { Iterator<DomainAttrItem> it = mDomainReverseProxyAttrs.iterator(); DomainAttrItem item; while (cache == null && it.hasNext()) { item = it.next(); if (item instanceof DomainAttrExceptionItem) { throw ((DomainAttrExceptionItem) item).exception; } if (!isRequiredAttrsValid(item, requiredAttrs)) { continue; } fillVarsWithDomainAttrs(item); cache = expandTemplateAndCache(temp, conf); conf.newLine(); } while (it.hasNext()) { item = it.next(); if (item instanceof DomainAttrExceptionItem) { throw ((DomainAttrExceptionItem) item).exception; } if (!isRequiredAttrsValid(item, requiredAttrs)) { continue; } fillVarsWithDomainAttrs(item); expandTempateFromCache(cache, conf); conf.newLine(); } } }
From source file:com.chinamobile.bcbsp.comm.MessageQueuesForDisk.java
/** * Cache the bucket of messages indexed by bucketIndex onto disk file. * @param queuesBuckets/*from w w w . ja v a 2 s . c o m*/ * @param bucketIndex * @param queuePath * @throws IOException */ private void saveBucket(ArrayList<BucketMeta> queuesBuckets, int bucketIndex, String queuePath) throws IOException { if (queuesBuckets.get(bucketIndex).countInMemory < this.countThresholdForBucket) { return; } LOG.info("[MessageQueuesForDisk] is saving the [" + queuePath + " Bucket-" + bucketIndex + "] >>> size = " + queuesBuckets.get(bucketIndex).countInMemory + "."); long start = System.currentTimeMillis(); /* Clock */ File messagesDataFileBucket; FileWriter fwMessagesData; BufferedWriter bwMessagesData; File messagesDataFileQueue = new File(this.messagesDataFile + "/" + queuePath); if (!messagesDataFileQueue.exists()) { if (!messagesDataFileQueue.mkdir()) { throw new IOException("Make dir " + messagesDataFileQueue + " fail!"); } } messagesDataFileBucket = new File(messagesDataFileQueue + "/" + "bucket-" + bucketIndex); boolean isNewFile = false; // The bucket file does not exit, create it. if (!messagesDataFileBucket.exists()) { if (!messagesDataFileBucket.createNewFile()) { throw new IOException("Create bucket file" + messagesDataFileBucket + " failed!"); } isNewFile = true; } // Append to the bucket file by line. fwMessagesData = new FileWriter(messagesDataFileBucket, true); bwMessagesData = new BufferedWriter(fwMessagesData, 65536); if (isNewFile) { // Write the file header. bwMessagesData.write(Constants.MSG_BUCKET_FILE_HEADER + "-" + queuePath + "-" + bucketIndex); } ConcurrentHashMap<String, ConcurrentLinkedQueue<IMessage>> queueMap = queuesBuckets .get(bucketIndex).queueMap; ConcurrentLinkedQueue<IMessage> tempQueue = null; Entry<String, ConcurrentLinkedQueue<IMessage>> entry = null; Iterator<Entry<String, ConcurrentLinkedQueue<IMessage>>> it = queueMap.entrySet().iterator(); // Traverse the map of queues and cache them to disk file. while (it.hasNext()) { entry = it.next(); String key = entry.getKey(); tempQueue = entry.getValue(); if (tempQueue.size() <= 0) { continue; } bwMessagesData.newLine(); bwMessagesData.write(key + Constants.KV_SPLIT_FLAG + queueToString(tempQueue)); this.sizeOfHashMapsInMem = this.sizeOfHashMapsInMem - (sizeOfRef + sizeOfInteger + sizeOfEmptyMessageQueue); } // while bwMessagesData.close(); fwMessagesData.close(); // Update the meta data of the bucket. BucketMeta meta = queuesBuckets.get(bucketIndex); // Update the size of messages data in memory. this.sizeOfMessagesDataInMem = this.sizeOfMessagesDataInMem - meta.lengthInMemory; this.countOfMessagesDataInMem = this.countOfMessagesDataInMem - meta.countInMemory; meta.onDiskFlag = true; meta.lengthInMemory = 0; meta.countInMemory = 0; meta.queueMap.clear(); this.writeDiskTime = this.writeDiskTime + (System.currentTimeMillis() - start); }
From source file:ch.rgw.tools.JdbcLink.java
public boolean dumpTable(BufferedWriter w, String name) throws Exception { Stm stm = getStatement();/*ww w . ja v a 2s. c om*/ ResultSet res = stm.query("SELECT * from " + name); ResultSetMetaData rm = res.getMetaData(); int cols = rm.getColumnCount(); String[] ColNames = new String[cols]; int[] colTypes = new int[cols]; w.write("CREATE TABLE " + name + "("); for (int i = 0; i < cols; i++) { ColNames[i] = rm.getColumnName(i + 1); colTypes[i] = rm.getColumnType(i + 1); w.write(ColNames[i] + " " + colTypes[i] + ",\n"); } w.write(");"); while ((res != null) && (res.next() == true)) { w.write("INSERT INTO " + name + " ("); for (int i = 0; i < cols; i++) { w.write(ColNames[i]); if (i < cols - 1) { w.write(","); } } w.write(") VALUES ("); for (int i = 0; i < cols; i++) { Object o = res.getObject(ColNames[i]); switch (JdbcLink.generalType(colTypes[i])) { case JdbcLink.INTEGRAL: if (o == null) { w.write("0"); } else { w.write(Integer.toString(((Integer) o).intValue())); } break; case JdbcLink.TEXT: if (o == null) { w.write(JdbcLink.wrap("null")); } else { w.write(JdbcLink.wrap((String) o)); } break; default: String t = o.getClass().getName(); log.log("Unknown type " + t, Log.ERRORS); throw new Exception("Cant write " + t); } if (i < cols - 1) { w.write(","); } } w.write(");"); w.newLine(); } res.close(); releaseStatement(stm); return true; }
From source file:io.snappydata.hydra.cluster.SnappyTest.java
protected void getSnappyJobOutputCollectively(String logFilekey, String fileName) { Set<String> snappyJobLogFiles = new LinkedHashSet<String>(); File fin = null;//from www. j ava2s . c o m try { Set<String> keys = SnappyBB.getBB().getSharedMap().getMap().keySet(); for (String key : keys) { if (key.startsWith(logFilekey)) { String logFilename = (String) SnappyBB.getBB().getSharedMap().getMap().get(key); Log.getLogWriter().info("Key Found...." + logFilename); snappyJobLogFiles.add(logFilename); } } File dir = new File("."); String dest = dir.getCanonicalPath() + File.separator + fileName; File file = new File(dest); if (!file.exists()) return; int num = (int) SnappyBB.getBB().getSharedCounters().incrementAndRead(SnappyBB.doneExecution); if (num == 1) { FileWriter fstream = new FileWriter(dest, true); BufferedWriter bw = new BufferedWriter(fstream); Iterator<String> itr = snappyJobLogFiles.iterator(); while (itr.hasNext()) { String userScript = itr.next(); String threadID = userScript.substring(userScript.lastIndexOf("_"), userScript.indexOf(".")); String threadInfo = "Thread" + threadID + " output:"; bw.write(threadInfo); bw.newLine(); String fileInput = snappyTest.getLogDir() + File.separator + userScript; fin = new File(fileInput); FileInputStream fis = new FileInputStream(fin); BufferedReader in = new BufferedReader(new InputStreamReader(fis)); String line = null; while ((line = in.readLine()) != null) { bw.write(line); bw.newLine(); } in.close(); } bw.close(); } } catch (FileNotFoundException e) { String s = "Unable to find file: " + fin; throw new TestException(s); } catch (IOException e) { String s = "Problem while writing to the file : " + fin; throw new TestException(s, e); } }
From source file:com.github.carlosrubio.org.apache.tools.ant.taskdefs.optional.net.FTP.java
/** * List information about a single file from the remote host. <code>filename</code> * may contain a relative path specification. <p> * * The file listing will then be retrieved using the entire relative path * spec - no attempt is made to change directories. It is anticipated that * this may eventually cause problems with some FTP servers, but it * simplifies the coding.</p>/* w w w.j a va 2 s. c o m*/ * @param ftp ftp client * @param bw buffered writer * @param filename the directory one wants to list * @throws IOException in unknown circumstances * @throws BuildException in unknown circumstances */ protected void listFile(FTPClient ftp, BufferedWriter bw, String filename) throws IOException, BuildException { if (verbose) { log("listing " + filename); } FTPFile[] ftpfiles = ftp.listFiles(resolveFile(filename)); if (ftpfiles != null && ftpfiles.length > 0) { String path = this.listingFullPath ? // "ftp://host.com//od/small/OfficersDirectors03_GL_f_20101120_1of1.xml.zip|23505456" listSingleFile(this.server, this.remotedir + "/" + filename, ftpfiles[0].getSize()) : // Default listing ftpfiles[0].toString(); bw.write(path); bw.newLine(); transferred++; } }
From source file:com.cloud.hypervisor.vmware.mo.VirtualMachineMO.java
@Deprecated public void setSnapshotDirectory(String snapshotDir) throws Exception { VirtualMachineFileInfo fileInfo = getFileInfo(); Pair<DatacenterMO, String> dcInfo = getOwnerDatacenter(); String vmxUrl = _context.composeDatastoreBrowseUrl(dcInfo.second(), fileInfo.getVmPathName()); byte[] vmxContent = _context.getResourceContent(vmxUrl); BufferedReader in = null;/*from w w w . j a v a 2 s .co m*/ BufferedWriter out = null; ByteArrayOutputStream bos = new ByteArrayOutputStream(); boolean replaced = false; try { in = new BufferedReader(new InputStreamReader(new ByteArrayInputStream(vmxContent))); out = new BufferedWriter(new OutputStreamWriter(bos)); String line; while ((line = in.readLine()) != null) { if (line.startsWith("workingDir")) { replaced = true; out.write(String.format("workingDir=\"%s\"", snapshotDir)); out.newLine(); } else { out.write(line); out.newLine(); } } if (!replaced) { out.newLine(); out.write(String.format("workingDir=\"%s\"", snapshotDir)); out.newLine(); } } finally { if (in != null) { in.close(); } if (out != null) { out.close(); } } _context.uploadResourceContent(vmxUrl, bos.toByteArray()); // It seems that I don't need to do re-registration. VMware has bug in writing the correct snapshot's VMDK path to // its disk backing info anyway. // redoRegistration(); }