List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:net.mohatu.bloocoin.miner.SubmitListClass.java
private void submit() { for (int i = 0; i < solved.size(); i++) { try {/*from w w w .ja v a 2 s .co m*/ Socket sock = new Socket(this.url, this.port); String result = new String(); DataInputStream is = new DataInputStream(sock.getInputStream()); DataOutputStream os = null; BufferedReader in = new BufferedReader(new InputStreamReader(is)); solution = solved.get(i); hash = DigestUtils.sha512Hex(solution); String command = "{\"cmd\":\"check" + "\",\"winning_string\":\"" + solution + "\",\"winning_hash\":\"" + hash + "\",\"addr\":\"" + MainView.getAddr() + "\"}"; os = new DataOutputStream(sock.getOutputStream()); os.write(command.getBytes()); String inputLine; while ((inputLine = in.readLine()) != null) { result += inputLine; } if (result.contains("\"success\": true")) { System.out.println("Result: Submitted"); MainView.updateStatusText(solution + " submitted"); Thread gc = new Thread(new CoinClass()); gc.start(); } else if (result.contains("\"success\": false")) { System.out.println("Result: Failed"); MainView.updateStatusText("Submission of " + solution + " failed, already exists!"); } is.close(); os.close(); os.flush(); sock.close(); } catch (UnknownHostException e) { MainView.updateStatusText("Submission of " + solution + " failed, connection failed!"); } catch (IOException e) { MainView.updateStatusText("Submission of " + solution + " failed, connection failed!"); } } Thread gc = new Thread(new CoinClass()); gc.start(); }
From source file:com.qut.middleware.spep.authn.bindings.impl.AuthnPostBindingImpl.java
public AuthnPostBindingImpl() { try {/*from w w w .j a v a2s . c om*/ InputStream inputStream = this.getClass().getResourceAsStream("samlPostRequestTemplate.html"); DataInputStream dataInputStream = new DataInputStream(inputStream); byte[] document = new byte[dataInputStream.available()]; dataInputStream.readFully(document); // Load the document as UTF-8 format and create a formatter for it. String samlResponseTemplate = new String(document, "UTF-8"); this.samlMessageFormat = new MessageFormat(samlResponseTemplate); this.logger.info("Created AuthnPostBindingImpl successfully"); } catch (IOException e) { throw new IllegalArgumentException("HTTP POST binding form could not be loaded due to an I/O error", e); } }
From source file:com.tvd.cocos2dx.popup.creator.file.FileUtils.java
public String readFromFile(String pFilePath) { FileInputStream fstream = null; DataInputStream inputStream = null; BufferedReader bufferedReader = null; mContent = ""; try {//from w ww . j a v a 2s .c om File file = new File(pFilePath); if (!file.exists()) { System.err.println("ERROR::readFromFile pFilePath = " + pFilePath); NotificationCenter.getInstance() .pushError("File " + pFilePath + " does not exist, create this file to continues"); return null; } fstream = new FileInputStream(file); inputStream = new DataInputStream(fstream); bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder builder = new StringBuilder(); String lineContent = bufferedReader.readLine(); while (lineContent != null) { builder.append(lineContent).append("\n"); lineContent = bufferedReader.readLine(); } mContent = builder.toString(); fstream.close(); inputStream.close(); bufferedReader.close(); } catch (IOException e) { e.printStackTrace(); } finally { } return mContent; }
From source file:com.rabbitmq.client.impl.SocketFrameHandler.java
/** * @param socket the socket to use//w w w . ja va 2 s . c o m */ public SocketFrameHandler(Socket socket) throws IOException { _socket = socket; _inputStream = new DataInputStream(new BufferedInputStream(socket.getInputStream())); _outputStream = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream())); this.socketFrameHandler = this; }
From source file:net.mohatu.bloocoin.miner.SubmitList.java
private void submit() { for (int i = 0; i < solved.size(); i++) { try {//from w w w.j a v a 2 s .c om Socket sock = new Socket(this.url, this.port); String result = new String(); DataInputStream is = new DataInputStream(sock.getInputStream()); DataOutputStream os = null; BufferedReader in = new BufferedReader(new InputStreamReader(is)); solution = solved.get(i); hash = DigestUtils.sha512Hex(solution); String command = "{\"cmd\":\"check" + "\",\"winning_string\":\"" + solution + "\",\"winning_hash\":\"" + hash + "\",\"addr\":\"" + Main.getAddr() + "\"}"; os = new DataOutputStream(sock.getOutputStream()); os.write(command.getBytes()); String inputLine; while ((inputLine = in.readLine()) != null) { result += inputLine; } if (result.contains("\"success\": true")) { System.out.println("Result: Submitted"); Main.updateStatusText(solution + " submitted", Color.blue); Thread gc = new Thread(new Coins()); gc.start(); } else if (result.contains("\"success\": false")) { System.out.println("Result: Failed"); Main.updateStatusText("Submission of " + solution + " failed, already exists!", Color.red); } is.close(); os.close(); os.flush(); sock.close(); } catch (UnknownHostException e) { e.printStackTrace(); Main.updateStatusText("Submission of " + solution + " failed, connection failed!", Color.red); } catch (IOException e) { e.printStackTrace(); Main.updateStatusText("Submission of " + solution + " failed, connection failed!", Color.red); } } Thread gc = new Thread(new Coins()); gc.start(); }
From source file:de.hybris.platform.jobs.RemovedItemPKProcessorTest.java
@Test public void testSkipofRefused() { final PK one = PK.createFixedUUIDPK(102, 1); final PK two = PK.createFixedUUIDPK(102, 2); final PK three = PK.createFixedUUIDPK(102, 3); final MediaModel mediaPk = new MediaModel(); final DataInputStream dis = new DataInputStream(buildUpStream(one, two, three)); Mockito.when(model.getItemPKs()).thenReturn(mediaPk); Mockito.when(mediaService.getStreamFromMedia(mediaPk)).thenReturn(dis); Mockito.when(model.getItemsRefused()).thenReturn(Integer.valueOf(10)); iterator.init(model);/*ww w . j ava 2 s. c o m*/ Assert.assertFalse("All iterations should be skipped ", iterator.hasNext()); }
From source file:WrappedInputStream.java
/** Constructs a wrapper for the given an input stream. */ public WrappedInputStream(InputStream stream) { super(stream); fDataInputStream = new DataInputStream(stream); }
From source file:Util.PacketGenerator.java
public static void GenerateTopology() { try {//ww w . ja va2 s . c om File file = new File("D:\\Mestrado\\Prototipo\\topologydata\\AS1239\\CONVERTED.POP.1239"); File newFile = new File("D:\\Mestrado\\SketchMatrix\\trunk\\AS1239_TOPOLOGY"); FileInputStream topologyFIS = new FileInputStream(file); DataInputStream topologyDIS = new DataInputStream(topologyFIS); BufferedReader topologyBR = new BufferedReader(new InputStreamReader(topologyDIS)); String topologyStr = topologyBR.readLine(); int numberOfEdges = 0; Set<Integer> nodes = new HashSet<>(); while (topologyStr != null) { String[] edge = topologyStr.split(" "); nodes.add(Integer.parseInt(edge[0])); nodes.add(Integer.parseInt(edge[1])); numberOfEdges++; topologyStr = topologyBR.readLine(); } topologyBR.close(); topologyDIS.close(); topologyFIS.close(); topologyFIS = new FileInputStream(file); topologyDIS = new DataInputStream(topologyFIS); topologyBR = new BufferedReader(new InputStreamReader(topologyDIS)); FileWriter topologyFW = new FileWriter(newFile); topologyStr = topologyBR.readLine(); topologyFW.write(nodes.size() + " " + numberOfEdges + "\n"); while (topologyStr != null) { String[] edge = topologyStr.split(" "); nodes.add(Integer.parseInt(edge[0])); nodes.add(Integer.parseInt(edge[1])); nodes.add(Integer.parseInt(edge[1])); topologyFW.write(Integer.parseInt(edge[0]) + " " + Integer.parseInt(edge[1]) + " 1\n"); topologyStr = topologyBR.readLine(); } topologyBR.close(); topologyDIS.close(); topologyFIS.close(); topologyFW.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.cloudera.recordbreaker.hive.RecordBreakerSerDe.java
/** * <code>initDeserializer</code> sets up the RecordBreaker-specific * (that is, specific to UnknownText) parts of the SerDe. In particular, * it loads in the text scanner description. */// www. j a v a 2 s . com void initDeserializer(String recordBreakerTypeTreePayload) { try { DataInputStream in = new DataInputStream(new FileInputStream(new File(recordBreakerTypeTreePayload))); this.typeTree = InferredType.readType(in); } catch (UnsupportedEncodingException uee) { uee.printStackTrace(); } catch (IOException iex) { iex.printStackTrace(); } }
From source file:com.android.development.ExceptionBrowser.java
@Override protected void onCreate(Bundle icicle) { super.onCreate(icicle); Cursor cursor = getContentResolver().query(Checkin.Crashes.CONTENT_URI, new String[] { Checkin.Crashes._ID, Checkin.Crashes.DATA }, null, null, null); if (cursor != null) { startManagingCursor(cursor);/*w w w. java 2 s . c o m*/ setListAdapter(new CursorAdapter(this, cursor, true) { public View newView(Context context, Cursor c, ViewGroup v) { return new CrashListItem(context); } public void bindView(View view, Context c, Cursor cursor) { CrashListItem item = (CrashListItem) view; try { String data = cursor.getString(1); CrashData crash = new CrashData(new DataInputStream( new ByteArrayInputStream(Base64.decodeBase64(data.getBytes())))); ThrowableData exc = crash.getThrowableData(); item.setText(exc.getType() + ": " + exc.getMessage()); item.setCrashData(crash); } catch (IOException e) { item.setText("Invalid crash: " + e); Log.e(TAG, "Invalid crash", e); } } }); } else { // No database, no exceptions, empty list. setListAdapter(new BaseAdapter() { public int getCount() { return 0; } public Object getItem(int position) { throw new AssertionError(); } public long getItemId(int position) { throw new AssertionError(); } public View getView(int position, View convertView, ViewGroup parent) { throw new AssertionError(); } }); } }