List of usage examples for java.io DataInputStream readUTF
public final String readUTF() throws IOException
readUTF
method of DataInput
. From source file:org.prorefactor.refactor.PUB.java
private void readFileIndex(DataInputStream in) throws IOException { int index;//from www . j a v a 2 s . c om String filename; for (;;) { index = in.readInt(); filename = in.readUTF(); if (index == -1) break; fileList.add(filename); fileIndexes.add(filename); } }
From source file:IntSort.java
public void readStream() { try {//from w w w . ja v a 2 s.com // Careful: Make sure this is big enough! // Better yet, test and reallocate if necessary byte[] recData = new byte[50]; // Read from the specified byte array ByteArrayInputStream strmBytes = new ByteArrayInputStream(recData); // Read Java data types from the above byte array DataInputStream strmDataType = new DataInputStream(strmBytes); if (rs.getNumRecords() > 0) { ComparatorInt comp = new ComparatorInt(); int i = 1; RecordEnumeration re = rs.enumerateRecords(null, comp, false); while (re.hasNextElement()) { // Get data into the byte array rs.getRecord(re.nextRecordId(), recData, 0); // Read back the data types System.out.println("Record #" + i++); System.out.println("Name: " + strmDataType.readUTF()); System.out.println("Dog: " + strmDataType.readBoolean()); System.out.println("Rank: " + strmDataType.readInt()); System.out.println("--------------------"); // Reset so read starts at beginning of array strmBytes.reset(); } comp.compareIntClose(); // Free enumerator re.destroy(); } strmBytes.close(); strmDataType.close(); } catch (Exception e) { db(e.toString()); } }
From source file:PersistentRankingMIDlet.java
public BookInfo getBookInfo(int id) throws RecordStoreException, IOException { byte[] bytes = store.getRecord(id); DataInputStream is = new DataInputStream(new ByteArrayInputStream(bytes)); String isbn = is.readUTF(); BookInfo info = new BookInfo(isbn); info.id = id;//from w w w. j a v a 2 s. c om info.title = is.readUTF(); info.ranking = is.readInt(); info.reviews = is.readInt(); info.lastRanking = is.readInt(); info.lastReviews = is.readInt(); return info; }
From source file:org.prorefactor.refactor.PUB.java
private void readStrings(DataInputStream in) throws IOException { int size = in.readInt(); stringArray = new String[size]; for (int i = 0; i < size; i++) { stringArray[i] = in.readUTF(); }//from w w w . j a v a2s.c om }
From source file:org.codehaus.groovy.grails.web.pages.GroovyPageMetaInfo.java
/** * Reads the static html parts from a file stored in a separate file in the same package as the precompiled GSP class * * @throws IOException// www.j av a2 s . c o m */ private void readHtmlData() throws IOException { String dataResourceName = resolveDataResourceName(HTML_DATA_POSTFIX); DataInputStream input = null; try { InputStream resourceStream = pageClass.getResourceAsStream(dataResourceName); if (resourceStream != null) { input = new DataInputStream(resourceStream); int arrayLen = input.readInt(); htmlParts = new String[arrayLen]; for (int i = 0; i < arrayLen; i++) { htmlParts[i] = input.readUTF(); } } } finally { IOUtils.closeQuietly(input); } }
From source file:org.bdval.cache.TableCache.java
/** * Retrieve a cached table from the cache. isTableCached should be called * before calling this to verify that the table is cached. Null will * be returned if the table wasn't in the cache or there was a problem * reading the table.//from www.j a va 2 s . c o m * * @param splitId The split id * @param splitType The Split type * @param datasetName The dataset name * @param geneListFilter A gene list. If not null, the gene list is queried with each double * column identifier to determine if the identifier is contained in the gene list. Columns * that do not match the gene list are not loaded. * @return the table read from the cache (or null if it could not be read) */ public Table getCachedTable(final int splitId, final String splitType, final String datasetName, final GeneList geneListFilter) { final File cachedTableFile = getCachedTableFile(splitId, splitType, datasetName); if (geneListFilter != null && !(geneListFilter instanceof FullGeneList)) { final ObjectSet<CharSequence> tableColumnIds = getTableColumnIds(splitId, splitType, datasetName); geneListFilter.calculateProbeSetSelection(tableColumnIds); } DataInputStream dataInput = null; try { dataInput = new DataInputStream(new FastBufferedInputStream(new FileInputStream(cachedTableFile))); final ArrayTable result = new ArrayTable(); final int numberOfColumns = dataInput.readInt(); LOG.info("Reading cached table with " + numberOfColumns + " columns"); for (int i = 0; i < numberOfColumns; i++) { final String colType = dataInput.readUTF(); final String colId = dataInput.readUTF(); if ("s".equals(colType)) { final int numStrings = dataInput.readInt(); resize(result, numStrings); final int columnIndex = result.addColumn(colId, String.class); for (int j = 0; j < numStrings; j++) { result.appendObject(columnIndex, dataInput.readUTF()); } } else if ("d".equals(colType)) { final int numDoubles = dataInput.readInt(); resize(result, numDoubles); if (geneListFilter != null && !geneListFilter.isProbesetInList(colId)) { // the column does not match the gene list. Skip this column // we don't need to read these doubles, just skip them; final int numBytes = Double.SIZE * numDoubles / 8; final int actualBytes = dataInput.skipBytes(numBytes); if (actualBytes != numBytes) { LOG.warn("actual bytes skipped (" + actualBytes + ") does" + "not equal expected of " + numBytes); } continue; } final int columnIndex = result.addColumn(colId, double.class); for (int j = 0; j < numDoubles; j++) { result.appendDoubleValue(columnIndex, dataInput.readDouble()); } } else { LOG.error("UNKNOWN COLUMN TYPE " + colType + " cannot read cached table from file " + filenameOf(cachedTableFile)); return null; } } return result; } catch (IOException e) { LOG.error(e); return null; } catch (TypeMismatchException e) { LOG.error("TypeMismatchException adding data to Table " + filenameOf(cachedTableFile), e); return null; } finally { IOUtils.closeQuietly(dataInput); } }
From source file:org.pentaho.di.trans.dataservice.jdbc.RemoteClientTest.java
@Test public void testLargeQuery() throws Exception { String sql = "SELECT * FROM myService\nWHERE id = 3 /" + StringUtils.repeat("*", 8000) + "/"; when(connection.getDebugTransFilename()).thenReturn(null); when(connection.getParameters()).thenReturn(ImmutableMap.<String, String>of()); when(httpClient.executeMethod(isA(PostMethod.class))).thenReturn(200); MockDataInput mockDataInput = new MockDataInput(); mockDataInput.writeUTF("Query Response"); when(execMethod.getResponseBodyAsStream()).thenReturn(mockDataInput.toDataInputStream()); DataInputStream queryResponse = remoteClient.query(sql, 200); verify(httpClient).executeMethod(httpMethodCaptor.capture()); PostMethod httpMethod = (PostMethod) httpMethodCaptor.getValue(); assertThat(httpMethod.getURI().toString(), equalTo("http://localhost:9080/pentaho-di/kettle/sql/")); assertThat(httpMethod.getRequestHeader("SQL"), is(nullValue())); assertThat(httpMethod.getRequestHeader("MaxRows"), is(nullValue())); assertThat(httpMethod.getParameter("SQL").getValue(), equalTo("SELECT * FROM myService WHERE id = 3 /" + StringUtils.repeat("*", 8000) + "/")); assertThat(httpMethod.getParameter("MaxRows").getValue(), equalTo("200")); assertThat(queryResponse.readUTF(), equalTo("Query Response")); }
From source file:tvbrowser.core.PluginLoader.java
/** * read the contents of a proxy file to get the necessary * information about the plugin managed by this proxy to recreate * the proxy without the plugin actually being loaded * * @param proxyFile//from w w w. j ava 2 s . c o m * @return pluginProxy */ private JavaPluginProxy readPluginProxy(File proxyFile) { DataInputStream in = null; try { in = new DataInputStream(new BufferedInputStream(new FileInputStream(proxyFile))); String name = in.readUTF(); String author = in.readUTF(); String description = in.readUTF(); String license = in.readUTF(); DummyPlugin.setCurrentVersion(new Version(in)); String pluginId = in.readUTF(); in.readLong(); // file size is unused String lcFileName = in.readUTF(); in.close(); // check existence of plugin file File pluginFile = new File(lcFileName); if (!pluginFile.canRead()) { deletePluginProxy(proxyFile); return null; } // everything seems fine, create plugin proxy and plugin info PluginInfo info = new PluginInfo(DummyPlugin.class, name, description, author, license); // now get icon String iconFileName = getProxyIconFileName(proxyFile); return new JavaPluginProxy(info, lcFileName, pluginId, iconFileName); } catch (Exception e) { if (in != null) { try { in.close(); } catch (IOException e1) { // ignore } } // delete proxy on read error, maybe the format has changed deletePluginProxy(proxyFile); return null; } }
From source file:PersistentRankingMIDlet.java
public boolean matches(byte[] book) { if (searchISBN != null) { try {/* w w w.ja v a 2 s . co m*/ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(book)); // Match based on the ISBN. return searchISBN.equals(stream.readUTF()); } catch (IOException ex) { System.err.println(ex); } } // Default is not to match return false; }
From source file:bankingclient.ChonThaoTacFrame.java
public ChonThaoTacFrame(NewOrOldAccFrame acc) { initComponents();/*from w w w . jav a2 s . c om*/ jTextField1.setText(""); jLabel4.setVisible(false); jComboBox2.setVisible(false); jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); jBt_xn2.setVisible(false); this.accList = null; this.cusList = null; this.noAcc = acc; this.tt = new Thong_Tin_TK(this); this.setVisible(false); jBt_xn1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (NumberUtils.isNumber(jTextField1.getText()) && (Long.parseLong(jTextField1.getText()) > 0)) { long currentMoney = 0; try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(8); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner lineScanner = new Scanner(din.readUTF()); currentMoney = Long.parseLong(lineScanner.nextLine()); System.out.println(currentMoney); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li kt ni mng,bn cn kim tra kt ni"); } if (jCheck_gt.isSelected()) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(5); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText() + "\n" + (noAcc.getCustomer())); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy ra...."); } JOptionPane.showMessageDialog(rootPane, "Gi Ti?n Thnh Cng..."); } if (jCheck_rt.isSelected()) { if ((Long.parseLong(jTextField1.getText()) <= currentMoney)) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(6); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + jTextField1.getText() + "\n" + (noAcc.getCustomer())); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy Ra....."); } JOptionPane.showMessageDialog(rootPane, "Rt Ti?n Thnh Cng ..."); } else { System.out.println("Khng Ti?n Trong ti khon.." + currentMoney); JOptionPane.showMessageDialog(null, "Ti Khon Khng ? ? Rt ..."); } } noAcc.setVisible(true); ChonThaoTacFrame.this.setVisible(false); } else { JOptionPane.showMessageDialog(rootPane, "Cn Nhp Li S Ti?n Cn Gi Hoc Rt.."); } } }); jBt_tt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { tt.setTk((String) jComboBox1.getSelectedItem()); tt.hienTenTk(); long currentMoney = 0; try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(8); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner lineScanner = new Scanner(din.readUTF()); currentMoney = Long.parseLong(lineScanner.nextLine()); // System.out.println(currentMoney); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li kt ni mng,bn cn kim tra kt ni"); } tt.hienSoDu(((Long) currentMoney).toString()); tt.setVisible(true); try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(10); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner cusScanner = new Scanner(din.readUTF()); while (cusScanner.hasNextLine()) { tt.addCus(cusScanner.nextLine()); } } catch (Exception ee) { ee.printStackTrace(); } tt.hienChuTaiKhoan(); try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(12); dout.writeUTF((String) jComboBox1.getSelectedItem()); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); Scanner dateScanner = new Scanner(din.readUTF()); int day = Integer.parseInt(dateScanner.nextLine()); int month = Integer.parseInt(dateScanner.nextLine()); int year = Integer.parseInt(dateScanner.nextLine()); String date = (day + "-" + month + "-" + year); tt.hienNgayLapTaiKhoan(date); while (dateScanner.hasNextLine()) { // System.out.println("aaa"); tt.addGiaoDich(dateScanner.nextLine()); } tt.hienGiaoDich(); } catch (Exception ex) { ex.printStackTrace(); } ChonThaoTacFrame.this.setVisible(false); } }); jBt_xn2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_tctk.isSelected()) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(7); dout.writeUTF((String) jComboBox1.getSelectedItem() + "\n" + (String) jComboBox2.getSelectedItem()); dout.flush(); } catch (Exception ex) { ex.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "C Li Kt Ni Xy Ra\n Thm Ch Tht Bi..."); } JOptionPane.showMessageDialog(rootPane, "Thm Ch Ti Khon Thnh Cng.."); } else { System.out.println("nothing to do..."); } } }); jBt_xtk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { try { Socket client = new Socket("113.22.46.207", 6013); DataOutputStream dout = new DataOutputStream(client.getOutputStream()); dout.writeByte(11); String sent = (String) (jComboBox1.getSelectedItem()) + "\n" + noAcc.getCustomer(); dout.writeUTF(sent); dout.flush(); DataInputStream din = new DataInputStream(client.getInputStream()); byte check = din.readByte(); if (check == 1) { JOptionPane.showMessageDialog(rootPane, "xoa tai khoan thanh cong"); } else { JOptionPane.showMessageDialog(rootPane, "<html>xoa tai khoan <b>khong</b> thanh cong <br> chi chu chinh moi co the xoa tai khoan</html>"); } } catch (Exception ee) { ee.printStackTrace(); JOptionPane.showMessageDialog(rootPane, "Li Kt Ni ,Vui Lng Kim Tra Li.."); } } }); /*dont touch*/ jBt_ql.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { noAcc.setVisible(true); ChonThaoTacFrame.this.setVisible(false); } }); /*dont touch*/ jComboBox1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); jComboBox2.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { } }); /*dont touch jcheckbox*/ jCheck_tctk.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_tctk.isSelected()) { jLabel4.setVisible(true); jComboBox2.setVisible(true); jBt_xn2.setVisible(true); } else { jLabel4.setVisible(false); jComboBox2.setVisible(false); jBt_xn2.setVisible(false); } } }); jCheck_gt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_gt.isSelected()) { if (jCheck_rt.isSelected()) { jCheck_rt.setSelected(false); } jLabel2.setVisible(true); jLabel3.setVisible(true); jTextField1.setVisible(true); jBt_xn1.setVisible(true); } else { jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); } } }); jCheck_rt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { if (jCheck_rt.isSelected()) { if (jCheck_gt.isSelected()) { jCheck_gt.setSelected(false); } jLabel2.setVisible(true); jLabel3.setVisible(true); jTextField1.setVisible(true); jBt_xn1.setVisible(true); } else { jLabel2.setVisible(false); jLabel3.setVisible(false); jTextField1.setVisible(false); jBt_xn1.setVisible(false); } } }); /*dont touch jcheckbox*/ }