List of usage examples for java.io ByteArrayOutputStream toByteArray
public synchronized byte[] toByteArray()
From source file:House.java
public static void main(String[] args) throws IOException, ClassNotFoundException { House house = new House(); List animals = new ArrayList(); animals.add(new Animal("Bosco the dog", house)); animals.add(new Animal("Ralph the hamster", house)); animals.add(new Animal("Fronk the cat", house)); System.out.println("animals: " + animals); ByteArrayOutputStream buf1 = new ByteArrayOutputStream(); ObjectOutputStream o1 = new ObjectOutputStream(buf1); o1.writeObject(animals);// w w w. j a v a2 s . co m o1.writeObject(animals); // Write a 2nd set // Write to a different stream: ByteArrayOutputStream buf2 = new ByteArrayOutputStream(); ObjectOutputStream o2 = new ObjectOutputStream(buf2); o2.writeObject(animals); // Now get them back: ObjectInputStream in1 = new ObjectInputStream(new ByteArrayInputStream(buf1.toByteArray())); ObjectInputStream in2 = new ObjectInputStream(new ByteArrayInputStream(buf2.toByteArray())); List animals1 = (List) in1.readObject(), animals2 = (List) in1.readObject(), animals3 = (List) in2.readObject(); System.out.println("animals1: " + animals1); System.out.println("animals2: " + animals2); System.out.println("animals3: " + animals3); }
From source file:Hex.java
public static void main(String[] args) { if (args.length != 3) { System.out.println("Usage: HexStrToBin enc/dec <infileName> <outfilename>"); System.exit(1);/*from w ww. j a v a 2 s .c om*/ } try { ByteArrayOutputStream os = new ByteArrayOutputStream(); InputStream in = new FileInputStream(args[1]); int len = 0; byte buf[] = new byte[1024]; while ((len = in.read(buf)) > 0) os.write(buf, 0, len); in.close(); os.close(); byte[] data = null; if (args[0].equals("dec")) data = decode(os.toString()); else { String strData = encode(os.toByteArray()); data = strData.getBytes(); } FileOutputStream fos = new FileOutputStream(args[2]); fos.write(data); fos.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:marytts.tools.analysis.CopySynthesis.java
/** * @param args//from w w w . j a v a 2 s . co m */ public static void main(String[] args) throws Exception { String wavFilename = null; String labFilename = null; String pitchFilename = null; String textFilename = null; String locale = System.getProperty("locale"); if (locale == null) { throw new IllegalArgumentException("No locale given (-Dlocale=...)"); } for (String arg : args) { if (arg.endsWith(".txt")) textFilename = arg; else if (arg.endsWith(".wav")) wavFilename = arg; else if (arg.endsWith(".ptc")) pitchFilename = arg; else if (arg.endsWith(".lab")) labFilename = arg; else throw new IllegalArgumentException("Don't know how to treat argument: " + arg); } // The intonation contour double[] contour = null; double frameShiftTime = -1; if (pitchFilename == null) { // need to create pitch contour from wav file if (wavFilename == null) { throw new IllegalArgumentException("Need either a pitch file or a wav file"); } AudioInputStream ais = AudioSystem.getAudioInputStream(new File(wavFilename)); AudioDoubleDataSource audio = new AudioDoubleDataSource(ais); PitchFileHeader params = new PitchFileHeader(); params.fs = (int) ais.getFormat().getSampleRate(); F0TrackerAutocorrelationHeuristic tracker = new F0TrackerAutocorrelationHeuristic(params); tracker.pitchAnalyze(audio); frameShiftTime = tracker.getSkipSizeInSeconds(); contour = tracker.getF0Contour(); } else { // have a pitch file -- ignore any wav file PitchReaderWriter f0rw = new PitchReaderWriter(pitchFilename); if (f0rw.contour == null) { throw new NullPointerException("Cannot read f0 contour from " + pitchFilename); } contour = f0rw.contour; frameShiftTime = f0rw.header.skipSizeInSeconds; } assert contour != null; assert frameShiftTime > 0; // The ALLOPHONES data and labels if (labFilename == null) { throw new IllegalArgumentException("No label file given"); } if (textFilename == null) { throw new IllegalArgumentException("No text file given"); } MaryTranscriptionAligner aligner = new MaryTranscriptionAligner(); aligner.SetEnsureInitialBoundary(false); String labels = MaryTranscriptionAligner.readLabelFile(aligner.getEntrySeparator(), aligner.getEnsureInitialBoundary(), labFilename); MaryHttpClient mary = new MaryHttpClient(); String text = FileUtils.readFileToString(new File(textFilename), "ASCII"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); mary.process(text, "TEXT", "ALLOPHONES", locale, null, null, baos); ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance(); docFactory.setNamespaceAware(true); DocumentBuilder builder = docFactory.newDocumentBuilder(); Document doc = builder.parse(bais); aligner.alignXmlTranscriptions(doc, labels); assert doc != null; // durations double[] endTimes = new LabelfileDoubleDataSource(new File(labFilename)).getAllData(); assert endTimes.length == labels.split(Pattern.quote(aligner.getEntrySeparator())).length; // Now add durations and f0 targets to document double prevEnd = 0; NodeIterator ni = MaryDomUtils.createNodeIterator(doc, MaryXML.PHONE, MaryXML.BOUNDARY); for (int i = 0; i < endTimes.length; i++) { Element e = (Element) ni.nextNode(); if (e == null) throw new IllegalStateException("More durations than elements -- this should not happen!"); double durInSeconds = endTimes[i] - prevEnd; int durInMillis = (int) (1000 * durInSeconds); if (e.getTagName().equals(MaryXML.PHONE)) { e.setAttribute("d", String.valueOf(durInMillis)); e.setAttribute("end", new Formatter(Locale.US).format("%.3f", endTimes[i]).toString()); // f0 targets at beginning, mid, and end of phone StringBuilder f0String = new StringBuilder(); double startF0 = getF0(contour, frameShiftTime, prevEnd); if (startF0 != 0 && !Double.isNaN(startF0)) { f0String.append("(0,").append((int) startF0).append(")"); } double midF0 = getF0(contour, frameShiftTime, prevEnd + 0.5 * durInSeconds); if (midF0 != 0 && !Double.isNaN(midF0)) { f0String.append("(50,").append((int) midF0).append(")"); } double endF0 = getF0(contour, frameShiftTime, endTimes[i]); if (endF0 != 0 && !Double.isNaN(endF0)) { f0String.append("(100,").append((int) endF0).append(")"); } if (f0String.length() > 0) { e.setAttribute("f0", f0String.toString()); } } else { // boundary e.setAttribute("duration", String.valueOf(durInMillis)); } prevEnd = endTimes[i]; } if (ni.nextNode() != null) { throw new IllegalStateException("More elements than durations -- this should not happen!"); } // TODO: add pitch values String acoustparams = DomUtils.document2String(doc); System.out.println("ACOUSTPARAMS:"); System.out.println(acoustparams); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Document document = new Document(); PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf")); ByteArrayOutputStream os = new ByteArrayOutputStream(); XmpWriter xmp = new XmpWriter(os); XmpSchema dc = new DublinCoreSchema(); XmpArray subject = new XmpArray(XmpArray.UNORDERED); subject.add("Metadata"); dc.setProperty(DublinCoreSchema.SUBJECT, subject); xmp.addRdfDescription(dc);//from w w w . j a v a2s .c om PdfSchema pdf = new PdfSchema(); pdf.setProperty(PdfSchema.KEYWORDS, "Hello World, XMP, Metadata"); pdf.setProperty(PdfSchema.VERSION, "1.4"); xmp.addRdfDescription(pdf); xmp.close(); writer.setXmpMetadata(os.toByteArray()); document.open(); document.add(new Paragraph("Hello World")); document.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); // Create a new document Document xmlDoc = builder.newDocument(); // Create root node for the document... Element root = xmlDoc.createElement("Players"); xmlDoc.appendChild(root);//from w w w . jav a2 s . c o m // Create a "player" node Element player = xmlDoc.createElement("player"); // Set the players ID attribute player.setAttribute("ID", "1"); // Create currentRank node... Element currentRank = xmlDoc.createElement("currentRank"); currentRank.setTextContent("1"); player.appendChild(currentRank); // Create previousRank node... Element previousRank = xmlDoc.createElement("previousRank"); previousRank.setTextContent("1"); player.appendChild(previousRank); // Create playerName node... Element playerName = xmlDoc.createElement("PlayerName"); playerName.setTextContent("Max"); player.appendChild(playerName); // Create Money node... Element money = xmlDoc.createElement("Money"); money.setTextContent("15"); player.appendChild(money); // Add the player to the root node... root.appendChild(player); ByteArrayOutputStream baos = null; baos = new ByteArrayOutputStream(); Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.INDENT, "yes"); tf.setOutputProperty(OutputKeys.METHOD, "xml"); tf.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4"); DOMSource domSource = new DOMSource(xmlDoc); StreamResult sr = new StreamResult(baos); tf.transform(domSource, sr); baos.flush(); System.out.println(new String(baos.toByteArray())); baos.close(); }
From source file:net.cloudkit.enterprises.ws.SuperPassParaProxyTest.java
public static void main(String[] args) throws Exception { // CodeLists_Const???XML? // MFT2008? RMFT8ChangeReasonCode (AlphaNumber) // 001 ?/*from w w w .jav a 2 s .c o m*/ // 002 // 003 ? // 004 ???? // 005 ???? // 006 ?????? // 007 ???? // 008 ???? // 009 ?????? // 010 ???? // 011 ??? // 012 ? // 013 ? // 014 ? // 015 ?? // 999 // // MFT2008 RMFT8DeclareTypeCode (AlphaNumber) // MT1401 ?? // MT2401 ??? // MT5401 ?? // MT5402 ?? // MT3402 ? // MT7402 ?? // MT8401 ?? // MT8402 ?? // MT8403 ??? // MT8404 ??? // MT4401 ?? // MT4402 ?? // MT4403 ?? // MT4404 ?? // MT4405 ?? // MT4406 ?? // // MFT2008 RMFT8DeclareTypeCodeStat (AlphaNumber) // MT1401 ?? // MT2401 ??? // MT5401 ?? // MT5402 ?? // MT3402 ? // MT7402 ?? // MT8401 ?? // MT8402 ?? // MT8403 ??? // MT8404 ??? // MT4401 ?? // MT4402 ?? // MT4403 ?? // MT4404 ?? // MT4405 ?? // MT4406 ?? // // MFT2008 RMFT8FunctionTypeCode (AlphaNumber) // 2 // 3 // T // 5 ? // 9 ??? // 0 ??? // 11 // // MFT2008 (AlphaNumber) RMFT8ReponseTypeCode // M1 M1- // M2 M2-?? // M3 QP // 01 01-? // 02 02- // 03 03-? // 11 11- // 12 12- // 13 13-?? // T T- // D D-? // E1 E1-?? // E2 E2-? // E3 E3-?? // E4 E4-? // // ? (AlphaNumber) MasterAffirmSign // 0 // 1 ? // 2 ? // // ? ? (AlphaNumber) DeclareType // 0 // 1 // // MFT2008?? RMFT8MobileTypeCode (AlphaNumber) // MT4403 ?? // MT4404 ?? // MT4405 ?? // MT4406 ?? // // ? RMFT8MobileFuncCode (AlphaNumber) // M1 // M2 ?? // M3 QP // 2 // 3 // T // 5 ? // 9 ? // 0 (??) // 11 URL url = new URL("http://ceesb.chinaport.gov.cn/SuperPassParaProxy/Proxy_Services/SuperPass_Proxy?wsdl"); QName qname = new QName("http://www.cneport.com/webservices/superpass", "SuperPass"); Service service = Service.create(url, qname); SuperPass superPass = service.getPort(SuperPass.class); /* String serviceName = "eport.superpass.pub.para.CustomsFlagStatus"; byte[] requestContext = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><RequestContext><Group name=\"SystemInfo\"><Key name=\"ClientId\">5300001128334</Key><Key name=\"CertNo\">c1f4bb</Key><Key name=\"SaicSysNo\">618882068</Key><Key name=\"DEP_IN_CODE\">5300</Key><Key name=\"REG_CO_CGAC\">4403941436</Key><Key name=\"ENT_SEQ_NO\">000000000000063462</Key><Key name=\"IcCode\">8800000246746</Key><Key name=\"OperatorName\"></Key><Key name=\"DEP_CODE_CHG\">5300</Key><Key name=\"NAME_FULL\">???</Key></Group><Group name=\"DataPresentation\"><Key name=\"SignatureAlgorithm\" /><Key name=\"EncryptAlgorithm\" /><Key name=\"CompressAlgorithm\" /></Group></RequestContext>".getBytes(); byte[] requestData = "<?xml version=\"1.0\"?>\n<CustomsFlagStatusRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<CustomsCode>5300</CustomsCode>\n</CustomsFlagStatusRequest>".getBytes(); */ // ?? String serviceName = "eport.superpass.pub.para.LoadIntoMemory"; byte[] requestContext = "<?xml version=\"1.0\" encoding=\"utf-8\" standalone=\"yes\"?><RequestContext><Group name=\"SystemInfo\"><Key name=\"ClientId\">5300001128334</Key><Key name=\"CertNo\">b6c29b</Key><Key name=\"SaicSysNo\">618882068</Key><Key name=\"DEP_IN_CODE\">5300</Key><Key name=\"REG_CO_CGAC\">4403941436</Key><Key name=\"ENT_SEQ_NO\">000000000000063462</Key><Key name=\"SessionId\">2015-7-14</Key><Key name=\"IcCode\">8910000270086</Key><Key name=\"OperatorName\">??</Key><Key name=\"DEP_CODE_CHG\">5300</Key><Key name=\"NAME_FULL\">???</Key></Group><Group name=\"DataPresentation\"><Key name=\"SignatureAlgorithm\" /><Key name=\"EncryptAlgorithm\" /><Key name=\"CompressAlgorithm\" /></Group></RequestContext>" .getBytes(); // ? MFT8TrayType // SELECT TRAY_CODE,TRAY_NAME FROM MFT8_TRAY_TYPE ORDER BY TRAY_CODE // ??? RMFT8TransportType // SELECT CODE, NAME FROM mft8_transport_type ORDER BY CODE // ? RMFT8CustomsCode // SELECT customs_CODE, customs_NAME FROM customs ORDER BY customs_CODE // ??(CN003) RMFT8PortCode // SELECT CODE, CHNAME FROM mft8_location_name ORDER BY CODE // ? RMFT8Curr // SELECT CODE, NAME FROM MFT8_ROAD_CURR ORDER BY CODE // ? RMFT8ReceiptPlace // SELECT CODE, NAME FROM mft8_entity ORDER BY CODE // ? RMFT8CountryCode // SELECT CODE, NAME FROM mft8_country_code ORDER BY CODE // ?? RMFT8CustomStatus // SELECT CODE, NAME FROM MFT8_ROAD_CUSTOMS_STATUS ORDER BY CODE // ?? RMFT8TransPayCode // SELECT CODE, NAME FROM MFT8_ROAD_PAYMENT_METHOD ORDER BY CODE // ??(CN005) RMFT8WrapTypeCode // SELECT CODE, NAME FROM mft8_packaging ORDER BY CODE // ??? RMFT8TransLicCode // SELECT CODE, NAME FROM MFT8_CONTR_CAR_COND ORDER BY CODE // ?? RMFT8PortWorkCode // SELECT CODE, NAME FROM MFT8_HAND_INSTR ORDER BY CODE // ?? RMFT8CommunicationCode // SELECT CODE, NAME FROM mft8_communi_type ORDER BY CODE // ? RMFT8PostCode // SELECT CODE, NAME FROM mft8_post_code ORDER BY CODE // RMFT8EquipSizeCode // SELECT CODE, SHAPE,LENGTH,HEIGHT,WIDTH FROM mft8_equip_size_type ORDER BY CODE // ??? RMFT8EquipSupCode // SELECT CODE, NAME FROM MFT8_EQUIP_SUP ORDER BY CODE // ?? RMFT8EquipFullCode // SELECT CODE, NAME FROM mft8_equip_full ORDER BY CODE // ?? RMFT8EquipSealCode // SELECT CODE, NAME FROM mft8_seal_agency ORDER BY CODE // ??? RMFT8DanGoodsCode // SELECT CODE, CHNAME FROM mft8_dan_goods ORDER BY CODE // ? RMFT8CusProCode // SELECT CODE, NAME FROM mft8_cus_procedure ORDER BY CODE // ?/? RMFT8TransportSplitCode // SELECT CODE, NAME FROM mft8_indication ORDER BY CODE // ?? RMFT8DamageAreaCode // SELECT CODE, NAME FROM MFT8_DAMAGE_AREA ORDER BY CODE // ?? RMFT8DamageTypeCode // SELECT CODE, NAME FROM MFT8_DAMAGE_TYPE_DES ORDER BY CODE // IATA?(UN005) RMFT8IATACode // SELECT CODE, NAME FROM mft8_iata_code ORDER BY CODE // ????(UN009) RMFT8LocodePort // SELECT CODE, NAME FROM mft8_un_locode_port ORDER BY CODE // RMFT8ComplexCode // SELECT CODE_TS, G_NAME FROM complex ORDER BY CODE_TS byte[] requestData = "<?xml version=\"1.0\"?>\n<LoadIntoMemoryRequest xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">\n<QuerySql>SELECT CODE, NAME FROM mft8_un_locode_port ORDER BY CODE</QuerySql>\n</LoadIntoMemoryRequest>" .getBytes(); Holder<byte[]> responseData = new Holder<byte[]>(); System.out.println(new String(superPass.service(serviceName, requestContext, requestData, responseData))); // deflate DeflateCompressorInputStream gis = new DeflateCompressorInputStream( new ByteArrayInputStream(responseData.value)); ByteArrayOutputStream baos = new ByteArrayOutputStream(); int count; byte data[] = new byte[1024]; while ((count = gis.read(data, 0, 1024)) != -1) { baos.write(data, 0, count); } gis.close(); data = baos.toByteArray(); baos.flush(); baos.close(); System.out.println(new String(data)); // System.out.println(new String(responseData.value, "UTF-8")); }
From source file:net.itransformers.bgpPeeringMap.DavidPiegzaFormatTransformer.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); XsltTransformer transformer = new XsltTransformer(); File xsltFileName1 = new File("/Users/niau/trunk/bgpPeeringMap/conf/xslt/david_piegza.xslt"); byte[] rawData = readRawDataFile("/Users/niau/test1/network/version1/undirected/imap.graphml"); ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData); transformer.transformXML(inputStream1, xsltFileName1, outputStream1, null, null); File outputFile1 = new File("/Users/niau/trunk/bgpPeeringMap/src/main/resources", "imap.xml"); FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray())); }
From source file:net.itransformers.bgpPeeringMap.BgpPeeringMapFromFile.java
public static void main(String[] args) throws Exception { Map<String, String> params = CmdLineParser.parseCmdLine(args); logger.info("input params" + params.toString()); final String settingsFile = params.get("-s"); if (settingsFile == null) { printUsage("bgpPeeringMap.properties"); return;/*from www . j ava2 s . c o m*/ } Map<String, String> settings = loadProperties(new File(System.getProperty("base.dir"), settingsFile)); logger.info("Settings" + settings.toString()); File outputDir = new File(System.getProperty("base.dir"), settings.get("output.dir")); System.out.println(outputDir.getAbsolutePath()); boolean result = outputDir.mkdir(); // if (!result) { // System.out.println("result:"+result); // System.out.println("Unable to create dir: "+outputDir); // return; // } File graphmlDir = new File(outputDir, settings.get("output.dir.graphml")); result = outputDir.mkdir(); // if (!result) { // System.out.println("Unable to create dir: "+graphmlDir); // return; // } XsltTransformer transformer = new XsltTransformer(); byte[] rawData = readRawDataFile(settings.get("raw-data-file")); logger.info("First-transformation has started with xsltTransformator " + settings.get("xsltFileName1")); ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); File xsltFileName1 = new File(System.getProperty("base.dir"), settings.get("xsltFileName1")); ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData); // transformer.transformXML(inputStream1, xsltFileName1, outputStream1, settings); logger.info("First transformation finished"); File outputFile1 = new File(graphmlDir, "bgpPeeringMap-intermediate.xml"); FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray())); logger.info("Second transformation started with xsltTransformator " + settings.get("xsltFileName2")); ByteArrayOutputStream outputStream2 = new ByteArrayOutputStream(); File xsltFileName2 = new File(System.getProperty("base.dir"), settings.get("xsltFileName2")); ByteArrayInputStream inputStream2 = new ByteArrayInputStream(outputStream1.toByteArray()); // transformer.transformXML(inputStream2, xsltFileName2, outputStream2, settings); logger.info("Second transformation finished"); File outputFile = new File(graphmlDir, "bgpPeeringMap.graphml"); File nodesFileListFile = new File(graphmlDir, "nodes-file-list.txt"); FileUtils.writeStringToFile(outputFile, new String(outputStream2.toByteArray())); logger.info("Output Graphml saved in a file in" + graphmlDir); FileUtils.writeStringToFile(nodesFileListFile, "bgpPeeringMap.graphml"); ByteArrayInputStream inputStream3 = new ByteArrayInputStream(outputStream2.toByteArray()); ByteArrayOutputStream outputStream3 = new ByteArrayOutputStream(); File xsltFileName3 = new File(System.getProperty("base.dir"), settings.get("xsltFileName3")); // transformer.transformXML(inputStream3, xsltFileName3, outputStream3); }
From source file:com.tc.simple.apn.quicktests.Test.java
/** * @param args// w w w . ja v a 2 s . co m */ public static void main(String[] args) { SSLSocket socket = null; try { String host = "gateway.sandbox.push.apple.com"; int port = 2195; String token = "de7f197546e41a76684f8e2d89f397ed165298d7772f4bd9b0f39c674b185b0f"; System.out.println(token.toCharArray().length); //String token = "8cebc7c08f79fa62f0994eb4298387ff930857ff8d14a50de431559cf476b223"; KeyStore keyStore = KeyStore.getInstance("PKCS12"); keyStore.load(Test.class.getResourceAsStream("egram-dev-apn.p12"), "xxxxxxxxx".toCharArray()); KeyManagerFactory keyMgrFactory = KeyManagerFactory .getInstance(KeyManagerFactory.getDefaultAlgorithm()); keyMgrFactory.init(keyStore, "xxxxxxxxx".toCharArray()); SSLContext sslContext = SSLContext.getInstance("TLS"); sslContext.init(keyMgrFactory.getKeyManagers(), null, null); SSLSocketFactory socketFactory = sslContext.getSocketFactory(); socket = (SSLSocket) socketFactory.createSocket(host, port); String[] cipherSuites = socket.getSupportedCipherSuites(); socket.setEnabledCipherSuites(cipherSuites); socket.startHandshake(); char[] t = token.toCharArray(); byte[] b = Hex.decodeHex(t); OutputStream outputstream = socket.getOutputStream(); String payload = "{\"aps\":{\"alert\":\"yabadabadooo\"}}"; int expiry = (int) ((System.currentTimeMillis() / 1000L) + 7200); ByteArrayOutputStream bout = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(bout); //command dos.writeByte(1); //id dos.writeInt(900); //expiry dos.writeInt(expiry); //token length. dos.writeShort(b.length); //token dos.write(b); //payload length dos.writeShort(payload.length()); //payload. dos.write(payload.getBytes()); byte[] byteMe = bout.toByteArray(); socket.getOutputStream().write(byteMe); socket.setSoTimeout(900); InputStream in = socket.getInputStream(); System.out.println(APNErrors.getError(in.read())); in.close(); outputstream.close(); } catch (Exception e) { e.printStackTrace(); } finally { try { socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:net.itransformers.bgpPeeringMap.ThirdTransformation.java
public static void main(String[] args) throws Exception { ByteArrayOutputStream outputStream1 = new ByteArrayOutputStream(); XsltTransformer transformer = new XsltTransformer(); File xsltFileName1 = new File("/Users/niau/trunk/bgpPeeringMap/conf/xslt/reorder.xslt"); byte[] rawData = readRawDataFile( "/Users/niau/trunk/bgpPeeringMap/src/main/resources/bgpPeeringMap.graphml"); ByteArrayInputStream inputStream1 = new ByteArrayInputStream(rawData); transformer.transformXML(inputStream1, xsltFileName1, outputStream1); File outputFile1 = new File("/Users/niau/trunk/bgpPeeringMap/src/main/resources", "bgpPeeringMap2.graphxml"); FileUtils.writeStringToFile(outputFile1, new String(outputStream1.toByteArray())); }