List of usage examples for java.io DataOutputStream DataOutputStream
public DataOutputStream(OutputStream out)
From source file:com.liferay.nativity.control.unix.UnixNativityControlBaseImpl.java
@Override public boolean connect() { try {/* ww w .j ava 2 s .c om*/ _commandSocket = new Socket("127.0.0.1", _commandSocketPort); _commandBufferedReader = new BufferedReader( new InputStreamReader(_commandSocket.getInputStream(), "UTF-8")); _commandOutputStream = new DataOutputStream(_commandSocket.getOutputStream()); _callbackSocket = new Socket("127.0.0.1", _callbackSocketPort); _callbackBufferedReader = new BufferedReader( new InputStreamReader(_callbackSocket.getInputStream(), "UTF-8")); _callbackOutputStream = new DataOutputStream(_callbackSocket.getOutputStream()); _callbackThread = new ReadThread(this); _callbackThread.start(); _connected = true; if (_logger.isDebugEnabled()) { _logger.debug("Successfully connected to command socket: {}", _commandSocketPort); _logger.debug("Successfully connected to service socket: {}", _callbackSocketPort); } return true; } catch (IOException e) { _logger.error(e.getMessage()); } _connected = false; return false; }
From source file:com.boubei.tss.modules.license.LicenseFactory.java
/** * ???// w w w .j ava 2s . com * ????hacker??license * @throws Exception */ public static void generateKey() throws Exception { KeyPairGenerator keyGen = KeyPairGenerator.getInstance(KEY_ALGORITHM); keyGen.initialize(1024, new SecureRandom()); KeyPair pair = keyGen.generateKeyPair(); PrivateKey priv = pair.getPrivate(); PublicKey pub = pair.getPublic(); log.info("?"); DataOutputStream out = new DataOutputStream(new FileOutputStream(PUBLIC_KEY_FILE)); out.writeBytes(EasyUtils.encodeHex(pub.getEncoded())); out.close(); log.info("??" + PUBLIC_KEY_FILE); out = new DataOutputStream(new FileOutputStream(PRIVATE_KEY_FILE)); out.writeBytes(EasyUtils.encodeHex(priv.getEncoded())); out.close(); log.info("??" + PRIVATE_KEY_FILE); }
From source file:com.cbagroup.sit.CreditTransfer.java
public String sendPOST() throws IOException, NoSuchAlgorithmException { String key = "api_key=cbatest123"; //String url = "http://developer.cbagroup.com/api/CreditTransfer?api_key=cbatest123"; String url = "http://developer.cbagroup.com/api/CreditTransfer?" + key; URL object = new URL(url); HttpURLConnection con = (HttpURLConnection) object.openConnection(); //add reuqest header con.setRequestMethod("POST"); //con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept", "application/json"); String urlParameters = "BankCode=Kenya&" + "BranchCode=COMBAPI&" + "Country=COMBAPI&" + "TranType=CreditTransfer&" + "Reference=Impalapay&" + "Currency=10.25&" + "Account=pay&" + "Amount=10.22&" + "Narration=payment&" + "Transaction Date=1.2.2017&"; // Send post request con.setDoOutput(true);//w w w .j a v a2 s .com DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + urlParameters); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); //print result System.out.println(response.toString()); //////////start //////////////////// String result = response.toString(); JSONParser parser = new JSONParser(); try { Object obj = parser.parse(result); JSONObject jsonObject = (JSONObject) obj; //System.out.println(jsonObject); long ResCode = (long) jsonObject.get("Response Code"); System.out.println(); System.out.println("Response Code : " + ResCode); System.out.println(); if (ResCode == 1) { System.out.println("#########################################################"); System.out.println("Fred hack Fail"); System.out.println(); long ResCode1 = (long) jsonObject.get("Response Code"); System.out.println(); System.out.println("Response Code : " + ResCode1); System.out.println(); String Ref = (String) jsonObject.get("Reference"); System.out.println(); System.out.println("Reference : " + Ref); System.out.println(); String Des = (String) jsonObject.get("Description"); System.out.println(); System.out.println("Description : " + Des); System.out.println(); } else { System.out.println("#########################################################"); System.out.println("Fred hack Success"); System.out.println(); long ResCode1 = (long) jsonObject.get("Response Code"); System.out.println(); System.out.println("Response Code : " + ResCode1); System.out.println(); String Ref = (String) jsonObject.get("Reference"); System.out.println(); System.out.println("Reference : " + Ref); System.out.println(); String Des = (String) jsonObject.get("Description"); System.out.println(); System.out.println("Description : " + Des); System.out.println(); } // long age = (Long) jsonObject.get("Description"); // System.out.println(age); // loop array // JSONArray msg = (JSONArray) jsonObject.get("messages"); // Iterator<String> iterator = msg.iterator(); // while (iterator.hasNext()) { // System.out.println(iterator.next()); //} } catch (ParseException e) { e.printStackTrace(); } return response.toString(); }
From source file:ca.weblite.contacts.webservice.CN1DataMapperMessageConverter.java
@Override protected void writeInternal(Object t, HttpOutputMessage hom) throws IOException, HttpMessageNotWritableException { DataOutputStream out = new DataOutputStream(hom.getBody()); System.out.println("Writing object of type " + t.getClass()); Map m = (Map) Mappers.getInstance().jsonify(t); System.out.println(m);/* w w w . jav a 2s .c o m*/ com.codename1.io.Util.writeObject(m, out); }
From source file:com.microsoft.tfs.client.eclipse.resourcedata.ResourceData.java
/** * @return this object serialized to a byte array, or <code>null</code> if * there was a problem serializing *//*from w w w. j a va2 s. c om*/ public byte[] toByteArray() { try { final ByteArrayOutputStream os = new ByteArrayOutputStream(); final DataOutputStream dos = new DataOutputStream(os); dos.writeUTF(serverItem); dos.writeInt(changesetId); dos.close(); return os.toByteArray(); } catch (final IOException e) { log.error("Error serializing", e); //$NON-NLS-1$ return null; } }
From source file:tachyon.master.RawTablesTest.java
@Test public void writeImageTest() throws IOException, TachyonException { // crate the RawTables, byte buffers, and output streams RawTables rt = new RawTables(new TachyonConf()); ByteBuffer bb1 = ByteBuffer.allocate(1); ByteBuffer bb2 = ByteBuffer.allocate(1); ByteBuffer bb3 = ByteBuffer.allocate(1); ByteArrayOutputStream os = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(os); ObjectMapper mapper = JsonObject.createObjectMapper(); ObjectWriter writer = mapper.writer(); // add elements to the RawTables rt.addRawTable(0, 1, bb1);/*from w w w .j a va 2 s. c om*/ rt.addRawTable(1, 1, bb2); rt.addRawTable(2, 1, bb3); // write the image rt.writeImage(writer, dos); List<Integer> ids = Arrays.asList(0, 1, 2); List<Integer> columns = Arrays.asList(1, 1, 1); List<ByteBuffer> data = Arrays.asList(bb1, bb2, bb3); // decode the written bytes ImageElement decoded = mapper.readValue(os.toByteArray(), ImageElement.class); // test the decoded ImageElement Assert.assertEquals(ids, decoded.get("ids", new TypeReference<List<Integer>>() { })); Assert.assertEquals(columns, decoded.get("columns", new TypeReference<List<Integer>>() { })); Assert.assertEquals(data, decoded.get("data", new TypeReference<List<ByteBuffer>>() { })); }
From source file:com.spotify.scio.coders.FloatCoder.java
@Override public void encode(Float value, OutputStream outStream, Context context) throws IOException, CoderException { if (value == null) { throw new CoderException("cannot encode a null float"); }/* w ww. j av a2 s. com*/ new DataOutputStream(outStream).writeFloat(value); }
From source file:org.floggy.synchronization.jme.server.SynchronizationServletTest.java
/** * DOCUMENT ME!/*from w w w . j a v a 2s. c o m*/ * * @param synchronizableClass DOCUMENT ME! * * @return DOCUMENT ME! * * @throws Exception DOCUMENT ME! */ public byte[] getContent(Class synchronizableClass) throws Exception { SynchronizableMetadataManager.init(); SynchronizableMetadata metadata = SynchronizableMetadataManager .getSynchronizableMetadata(synchronizableClass.getName()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); dos.flush(); dos.writeUTF(metadata.toJSON()); return baos.toByteArray(); }
From source file:ja.lingo.engine.searchindex.NodeSerializer.java
public NodeSerializer(String fileName) throws IOException { Arguments.assertNotNull("fileName", fileName); this.fileName = fileName; tempFileName = EngineFiles.createTemp("search.index"); tempDos = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(tempFileName))); timeMeasurer = new TimeMeasurer(false); }
From source file:pl.edu.agh.BackgroundServiceConnection.java
/** * Compares sent hash to the one in database */// w ww .ja v a 2 s . co m public void run() { while (true) { try { LOGGER.info("Accepting connections on port: " + serverPort); Socket client = serverSocket.accept(); BufferedReader in = new BufferedReader(new InputStreamReader(client.getInputStream())); String message = in.readLine(); DataOutputStream out = new DataOutputStream(client.getOutputStream()); LOGGER.info("Daemon message: " + message); String[] data = message.trim().split("\\|"); try { Service service = serviceDAO.getById(Integer.parseInt(data[1])); if (!data[0].equalsIgnoreCase(service.getPassword())) throw new IllegalArgumentException("Daemon password: " + data[0] + " does not match server password: " + service.getPassword()); out.writeBytes("OK\r\n"); } catch (Exception e) { LOGGER.error("Could not find server: " + message.trim(), e); out.writeBytes("ERROR\r\n"); } in.close(); out.close(); client.close(); } catch (Exception e) { LOGGER.error("Error connecting with server: " + e.getMessage()); } } }