List of usage examples for java.io ByteArrayInputStream ByteArrayInputStream
public ByteArrayInputStream(byte buf[])
From source file:Main.java
public static Drawable getDrawableByByte(byte[] bts) { ByteArrayInputStream baInputStream = new ByteArrayInputStream(bts); return Drawable.createFromStream(baInputStream, "img"); }
From source file:Main.java
/** * @param b/*ww w. j a v a 2 s .c o m*/ * @return */ public static String getShi(byte[] buf) { StringBuilder builder = new StringBuilder(); ByteArrayInputStream input = new ByteArrayInputStream(buf); int i = 0; while ((i = input.read()) != -1) { builder.append(i); } return builder.toString(); }
From source file:Main.java
public static Object deserializable(byte[] bytes) { Object obj = null;//from w ww . j ava 2s . c om try { ByteArrayInputStream bis = new ByteArrayInputStream(bytes); ObjectInputStream ois = new ObjectInputStream(bis); obj = ois.readObject(); bis.close(); ois.close(); } catch (Exception e) { System.out.println("tanslation " + e.getMessage()); e.printStackTrace(); } return obj; }
From source file:Main.java
public static InputStream byteToInputSteram(byte[] data) { InputStream is = null;// ww w. j a v a 2s .c o m if (null != data && data.length > 0) { is = new ByteArrayInputStream(data); } return is; }
From source file:Main.java
public static Drawable byteToDrawable(byte[] byteArray) { ByteArrayInputStream ins = null; if (byteArray != null) ins = new ByteArrayInputStream(byteArray); return Drawable.createFromStream(ins, null); }
From source file:Main.java
public static Drawable byteToDrawable(byte[] byteArray) { ByteArrayInputStream ins = null; if (byteArray != null) { ins = new ByteArrayInputStream(byteArray); }//from www. j ava 2 s . com return Drawable.createFromStream(ins, null); }
From source file:com.jt.https.test.send.java
public static void main(String[] args) throws Exception { //final String xml = "<?xml version=\"1.0\" encoding=\"utf-8\"?><ChinaTourinsApply xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"><Head><UserId>0000000000</UserId><CommandId>CTAA0001</CommandId><SeqNo>JT2014_0000000263863</SeqNo></Head><Body><Apply><ApplyId>1201201407256948</ApplyId><TravelAgencyInfo><Id>1129035</Id><Name>???</Name><Address>?45?</Address><Zipcode>310000</Zipcode><Telphone>0571-63700288</Telphone><License>L-ZJ00295</License><OrgCode>79093228-2</OrgCode><OutboundTourismCredentials>N</OutboundTourismCredentials><LastYearTouristAmount>0.0</LastYearTouristAmount><LastYearRevenue>0-600</LastYearRevenue><last3YearAccidents>N</last3YearAccidents><Last1YearAccidentsFee>0.0</Last1YearAccidentsFee><Last2YearAccidentsFee>0.0</Last2YearAccidentsFee><Last3YearAccidentsFee>0.0</Last3YearAccidentsFee><Contact><Name></Name><Telphone>0571-63700288</Telphone><Mail>385816647@qq.ocm</Mail><Fax>0571-63700288</Fax></Contact><Branches /><Location><ProvinceId>12</ProvinceId><ProvinceName>?</ProvinceName><CityId>1201</CityId><CityName>?</CityName></Location><Properties><Key Name=\"LastApplyNo\" /><Key Name=\"LastPolicyNo\" /><Key Name=\"NewNum\" /><Key Name=\"NewLocation\" /></Properties><Last1YearPolicyNoList><Last1YearPolicyNoInfo><UserId /><PolicyNo /></Last1YearPolicyNoInfo></Last1YearPolicyNoList></TravelAgencyInfo><InsurancePolicyInfo><BeginDate>20140801</BeginDate><EndDate>20141231</EndDate><InsuranceDays>153</InsuranceDays><Renewal>N</Renewal><IssuingCompanyId>2014004</IssuingCompanyId><IssuingCompanyName>?????</IssuingCompanyName><IssuingGeneralCompanyName>???</IssuingGeneralCompanyName><RetroactiveDate>20140801</RetroactiveDate><MainInsurance><EachAccidentLiabilityLimit>20141000</EachAccidentLiabilityLimit><EachAccidentEveryLiabilityLimit>20142004</EachAccidentEveryLiabilityLimit><Properties><Key Name=\"MainPremium\">3135.4509</Key></Properties></MainInsurance><AdditionalInfo><Properties /></AdditionalInfo><PayDate>20140730</PayDate><PremiumInfo><PremiumAdjustmentFactor><YearTouristAmountRatio>-0.15</YearTouristAmountRatio><DistrictRatio>0</DistrictRatio><EachAccidentEveryLiabilityLimitRatio>0.1</EachAccidentEveryLiabilityLimitRatio><LossRatio>0</LossRatio><PreviousLossRatio>0</PreviousLossRatio><AdditionalRatio>0</AdditionalRatio><RiskControlRatio>0</RiskControlRatio><LoyaltyRatio>0</LoyaltyRatio><CoverageRateSystem>0</CoverageRateSystem><DatePreferentialRatio /></PremiumAdjustmentFactor><PremiumDistribution><TotalPremium>3135.45</TotalPremium><Distribution><RenBao CompanyId=\"2014004\">1442.30</RenBao><TaiBao CompanyId=\"2014058\">501.67</TaiBao><RenShou CompanyId=\"2014049\">250.84</RenShou><PingAn CompanyId=\"2014060\">344.90</PingAn><DaDi CompanyId=\"2014045\">282.19</DaDi><TaiPing CompanyId=\"2014039\">313.55</TaiPing></Distribution></PremiumDistribution><PremiumAdjust><RiskControl>0</RiskControl><Prepaid /></PremiumAdjust></PremiumInfo></InsurancePolicyInfo></Apply></Body></ChinaTourinsApply>"; final String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><ChinaTourinsResponse><Head><UserId>String</UserId><CommandId>String</CommandId><SeqNo>String</SeqNo><Ref-SeqNo>String</Ref-SeqNo></Head><Body><Apply><ApplyId>String</ApplyId><TravelAgencyId>String</TravelAgencyId><ResponseCode>String</ResponseCode><ResponseMessage>String</ResponseMessage><PolicyNo>String</PolicyNo><UpdateNo>String</UpdateNo><Fee>String</Fee><IssuingDate>String</IssuingDate><ElectricalDocument>String</ElectricalDocument></Apply></Body><IssuingCompany><Name>String</Name><Address>String</Address><Zipcode>String</Zipcode><Telphone>String</Telphone><Contact><Name>String</Name><Telphone>String</Telphone><Mail>String</Mail><Fax>String</Fax></Contact><Ccheck>String</Ccheck><Cbill>String</Cbill><Agent>String</Agent></IssuingCompany></ChinaTourinsResponse>"; WebInsuranceExchangeStub client = new WebInsuranceExchangeStub( "http://localhost/exchange/webservices/webInsuranceExchange"); com.jt.https.test.WebInsuranceExchangeStub.PolicyApplyConfirm post = new com.jt.https.test.WebInsuranceExchangeStub.PolicyApplyConfirm(); post.setUserId(""); DataHandler param = new DataHandler(new DataSource() { public InputStream getInputStream() { return new ByteArrayInputStream(xml.getBytes(Charset.forName("UTF-8"))); }/* w w w . j a va 2 s . co m*/ public OutputStream getOutputStream() { return null; } public String getContentType() { return ""; } public String getName() { return ""; } }); post.setConfirmMessage(param); com.jt.https.test.WebInsuranceExchangeStub.PolicyApplyConfirmResponse response = client .policyApplyConfirm(post); InputStream is = response.getResponseMessage().getInputStream(); String xml_result = ToolsUtils.ConvertStreamToString(is); System.out.println(xml_result); //PostTo(xml); }
From source file:Main.java
public static Object byteToObject(byte[] bytes) throws Exception { ObjectInputStream ois = null; try {/* w ww . j a v a 2 s. c om*/ ois = new ObjectInputStream(new ByteArrayInputStream(bytes)); return ois.readObject(); } finally { if (ois != null) ois.close(); } }
From source file:Main.java
public static Object deserialize(byte[] array) throws Exception { //System.err.println("neser#"+new String(array)); ObjectInputStream rin = new ObjectInputStream(new ByteArrayInputStream(array)); Object obj = rin.readObject(); rin.close();// w w w . j a v a 2s .com //System.err.println("neser##"+obj); return obj; }
From source file:Main.java
public static String uncompress(String str) throws IOException { if (str == null || str.length() == 0) { return str; }/*w ww.j a v a 2 s . com*/ ByteArrayInputStream in = new ByteArrayInputStream(str.getBytes("UTF-8")); return uncompress(in); }