List of usage examples for java.io DataInputStream DataInputStream
public DataInputStream(InputStream in)
From source file:com.cloudera.impala.security.DelegationTokenTest.java
@Test public void TestStartSecretManager() throws IOException { DelegationTokenSecretManager mgr = new DelegationTokenSecretManager(0, 60 * 60 * 1000, 60 * 60 * 1000, 0); mgr.startThreads();//w w w . j av a 2 s. c om String userName = UserGroupInformation.getCurrentUser().getUserName(); // Create a token for user. String tokenStrForm = mgr.getDelegationToken(userName); Token<DelegationTokenIdentifier> t = new Token<DelegationTokenIdentifier>(); t.decodeFromUrlString(tokenStrForm); // Check the token contains the proper username. DelegationTokenIdentifier d = new DelegationTokenIdentifier(); d.readFields(new DataInputStream(new ByteArrayInputStream(t.getIdentifier()))); assertTrue("Usernames don't match", userName.equals(d.getUser().getShortUserName())); assertEquals(d.getSequenceNumber(), 1); byte[] password = mgr.retrievePassword(d); assertEquals(password.length, t.getPassword().length); for (int i = 0; i < t.getPassword().length; ++i) { assertEquals(t.getPassword()[i], password[i]); } mgr.stopThreads(); }
From source file:com.csc.fi.ioapi.utils.JerseyJsonLDClient.java
public static Boolean readBooleanFromURL(String url) { try {//from w w w .j a va 2 s.c o m Client client = ClientBuilder.newClient(); WebTarget target = client.target(url); Response response = target.request("application/json").get(); if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) { logger.info("Failed to read boolean from: " + url + " " + response.getStatus()); return Boolean.FALSE; } DataInputStream dis = new DataInputStream(response.readEntity(InputStream.class)); return new Boolean(dis.readBoolean()); } catch (Exception ex) { logger.info("Failed in reading boolean from URL ... returning false"); return Boolean.FALSE; } }
From source file:com.bigdata.dastor.streaming.StreamInitiateVerbHandler.java
public void doVerb(Message message) { byte[] body = message.getMessageBody(); ByteArrayInputStream bufIn = new ByteArrayInputStream(body); if (logger.isDebugEnabled()) logger.debug(String.format("StreamInitiateVerbeHandler.doVerb %s %s %s", message.getVerb(), message.getMessageId(), message.getMessageType())); try {//from ww w . java2 s. c om StreamInitiateMessage biMsg = StreamInitiateMessage.serializer() .deserialize(new DataInputStream(bufIn)); PendingFile[] pendingFiles = biMsg.getStreamContext(); if (pendingFiles.length == 0) { if (logger.isDebugEnabled()) logger.debug("no data needed from " + message.getFrom()); if (StorageService.instance.isBootstrapMode()) StorageService.instance.removeBootstrapSource(message.getFrom(), new String(message.getHeader(StreamOut.TABLE_NAME))); return; } Map<String, String> fileNames = getNewNames(pendingFiles); Map<String, String> pathNames = new HashMap<String, String>(); for (String ssName : fileNames.keySet()) pathNames.put(ssName, DatabaseDescriptor.getNextAvailableDataLocation()); /* * For each of stream context's in the incoming message * generate the new file names and store the new file names * in the StreamContextManager. */ for (PendingFile pendingFile : pendingFiles) { CompletedFileStatus streamStatus = new CompletedFileStatus(pendingFile.getTargetFile(), pendingFile.getExpectedBytes()); String file = getNewFileNameFromOldContextAndNames(fileNames, pathNames, pendingFile); if (logger.isDebugEnabled()) logger.debug("Received Data from : " + message.getFrom() + " " + pendingFile.getTargetFile() + " " + file); pendingFile.setTargetFile(file); addStreamContext(message.getFrom(), pendingFile, streamStatus); } StreamInManager.registerStreamCompletionHandler(message.getFrom(), new StreamCompletionHandler()); if (logger.isDebugEnabled()) logger.debug("Sending a stream initiate done message ..."); Message doneMessage = new Message(FBUtilities.getLocalAddress(), "", StorageService.Verb.STREAM_INITIATE_DONE, new byte[0]); MessagingService.instance.sendOneWay(doneMessage, message.getFrom()); } catch (IOException ex) { throw new IOError(ex); } }
From source file:com.alibaba.dragoon.common.protocol.transport.socket.SocketSessionImpl.java
public SocketSessionImpl(Socket socket, AtomicLong receivedBytes, AtomicLong receivedMessages, AtomicLong sentBytes, AtomicLong sentMessages) { super();//from w w w . jav a 2 s .co m this.socket = socket; state = State.Established; this.receivedBytes = receivedBytes; this.receivedMessages = receivedMessages; this.sentBytes = sentBytes; this.sentMessages = sentMessages; try { dataInput = new DataInputStream(socket.getInputStream()); writer = new DataOutputStream(socket.getOutputStream()); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e.getMessage(), e); } catch (IOException e) { throw new IllegalStateException(e.getMessage(), e); } }
From source file:com.nemesis.admin.UploadServlet.java
/** * @param request//from w ww . j a va 2 s. co m * @param response * @throws javax.servlet.ServletException * @throws java.io.IOException * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse * response) * */ @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { if (request.getParameter("getfile") != null && !request.getParameter("getfile").isEmpty()) { File file = getFile(request, request.getParameter("getfile")); if (file.exists()) { int bytes = 0; try (ServletOutputStream op = response.getOutputStream()) { response.setContentType(getMimeType(file)); response.setContentLength((int) file.length()); response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\""); byte[] bbuf = new byte[1024]; DataInputStream in = new DataInputStream(new FileInputStream(file)); while ((in != null) && ((bytes = in.read(bbuf)) != -1)) { op.write(bbuf, 0, bytes); } in.close(); op.flush(); } } } else if (request.getParameter("delfile") != null && !request.getParameter("delfile").isEmpty()) { File file = getFile(request, request.getParameter("delfile")); if (file.exists()) { file.delete(); // TODO:check and report success } } else if (request.getParameter("getthumb") != null && !request.getParameter("getthumb").isEmpty()) { File file = getFile(request, request.getParameter("getthumb")); if (file.exists()) { System.out.println(file.getAbsolutePath()); String mimetype = getMimeType(file); if (mimetype.endsWith("png") || mimetype.endsWith("jpeg") || mimetype.endsWith("jpg") || mimetype.endsWith("gif")) { BufferedImage im = ImageIO.read(file); if (im != null) { int newWidth = 75; if (request.getParameter("w") != null) { try { newWidth = Integer.parseInt(request.getParameter("w")); } catch (Exception e) { //Se mantiene el valor por defecto de 75 } } BufferedImage thumb = Scalr.resize(im, newWidth); if (request.getParameter("h") != null) { try { thumb = Scalr.crop(thumb, newWidth, Integer.parseInt(request.getParameter("h"))); } catch (IllegalArgumentException | ImagingOpException e) { //Se mantienen las proporciones. } } ByteArrayOutputStream os = new ByteArrayOutputStream(); if (mimetype.endsWith("png")) { ImageIO.write(thumb, "PNG", os); response.setContentType("image/png"); } else if (mimetype.endsWith("jpeg")) { ImageIO.write(thumb, "jpg", os); response.setContentType("image/jpeg"); } else if (mimetype.endsWith("jpg")) { ImageIO.write(thumb, "jpg", os); response.setContentType("image/jpeg"); } else { ImageIO.write(thumb, "GIF", os); response.setContentType("image/gif"); } try (ServletOutputStream srvos = response.getOutputStream()) { response.setContentLength(os.size()); response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\""); os.writeTo(srvos); srvos.flush(); } } } } // TODO: check and report success } else { PrintWriter writer = response.getWriter(); writer.write("call POST with multipart form data"); } }
From source file:net.contextfw.web.application.internal.development.ReloadingClassLoader.java
private byte[] loadClassData(String className) throws IOException { InputStream stream = super.getResourceAsStream(className.replaceAll("\\.", "/") + ".class"); if (stream != null) { DataInputStream dis = new DataInputStream(stream); // NOSONAR byte buff[] = IOUtils.toByteArray(stream); dis.close();// w w w . ja va2 s . c o m return buff; } else { return null; } }
From source file:com.splunk.hunk.input.packet.PcapRecordReader.java
@Override public void vixInitialize(VixInputSplit split, TaskAttemptContext context) throws IOException, InterruptedException { //gLogger.info("takashi:TgzPacketRecordReader:vixInitialize is called"); FileSystem fs = FileSystem.get(context.getConfiguration()); fsDataIn = fs.open(split.getPath()); pcapReader = initPcapReader(packet_type_class, new DataInputStream(fsDataIn)); packetIterator = pcapReader.iterator(); totalBytesToRead = split.getLength() - split.getStart(); objectPreProcessor = new PacketEventProcessor(); }
From source file:bankingclient.ChonThaoTacFrame.java
public ChonThaoTacFrame(NewOrOldAccFrame acc) { initComponents();/*from w ww . j a va 2 s. c o m*/ 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*/ }
From source file:eu.stratosphere.pact.runtime.task.util.SerializationCopier.java
/** * Creates a SerializationCopier with an byte array of specified size. * // w w w .j av a 2 s. co m * @param initialCopySize * Initial size of the byte array that stores the serialized copy. */ public SerializationCopier(int initialCopySize) { serializedCopy = new byte[initialCopySize]; baos = new ByteArrayOutputStream(); dos = new DataOutputStream(baos); bais = new ByteArrayInputStream(serializedCopy); dis = new DataInputStream(bais); }
From source file:com.vrs.qrw100s.NetworkReader.java
@Override public void run() { Thread.currentThread().setName("Network Reader"); HttpResponse res;//w ww . j a v a 2 s.c om DefaultHttpClient httpclient = new DefaultHttpClient(); HttpParams httpParams = httpclient.getParams(); HttpConnectionParams.setConnectionTimeout(httpParams, 5 * 1000); HttpConnectionParams.setSoTimeout(httpParams, 10 * 1000); Log.d(TAG, "1. Sending http request"); try { res = httpclient.execute(new HttpGet(URI.create(myURL))); Log.d(TAG, "2. Request finished, status = " + res.getStatusLine().getStatusCode()); if (res.getStatusLine().getStatusCode() == 401) { return; } DataInputStream bis = new DataInputStream(res.getEntity().getContent()); ByteArrayOutputStream jpgOut = new ByteArrayOutputStream(10000); int prev = 0; int cur; while ((cur = bis.read()) >= 0 && _runThread) { if (prev == 0xFF && cur == 0xD8) { // reset the output stream if (!skipFrame) { jpgOut.reset(); jpgOut.write((byte) prev); } } if (!skipFrame) { if (jpgOut != null) { jpgOut.write((byte) cur); } } if (prev == 0xFF && cur == 0xD9) { if (!skipFrame) { synchronized (curFrame) { curFrame = jpgOut.toByteArray(); } skipFrame = true; Message threadMessage = mainHandler.obtainMessage(); threadMessage.obj = curFrame; mainHandler.sendMessage(threadMessage); } else { if (skipNum < frameDecrement) { skipNum++; } else { skipNum = 0; skipFrame = false; } } } prev = cur; } } catch (ClientProtocolException e) { Log.d(TAG, "Request failed-ClientProtocolException", e); } catch (IOException e) { Log.d(TAG, "Request failed-IOException", e); } }