List of usage examples for java.io ByteArrayInputStream read
public synchronized int read(byte b[], int off, int len)
From source file:com.polyvi.xface.util.XFileUtils.java
/** * /*from w w w .ja v a 2 s. c o m*/ * * @param filePath * ? * @param data * ?? * @return ?? */ public static long write(String fileName, String data, int position) throws FileNotFoundException, IOException { boolean append = false; if (position > 0) { truncateFile(fileName, position); append = true; } byte[] rawData = data.getBytes(); ByteArrayInputStream in = new ByteArrayInputStream(rawData); FileOutputStream out = new FileOutputStream(fileName, append); byte buff[] = new byte[rawData.length]; in.read(buff, 0, buff.length); out.write(buff, 0, rawData.length); out.flush(); out.close(); return data.length(); }
From source file:com.codebutler.farebot.card.desfire.settings.StandardDesfireFileSettings.java
StandardDesfireFileSettings(ByteArrayInputStream stream) { super(stream); byte[] buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf);//from w w w . j a v a 2 s .c om mFileSize = Utils.byteArrayToInt(buf); }
From source file:com.codebutler.farebot.card.desfire.settings.RecordDesfireFileSettings.java
public RecordDesfireFileSettings(ByteArrayInputStream stream) { super(stream); byte[] buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf);//from ww w.j a va 2 s .co m mRecordSize = Utils.byteArrayToInt(buf); buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); mMaxRecords = Utils.byteArrayToInt(buf); buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); mCurRecords = Utils.byteArrayToInt(buf); }
From source file:com.codebutler.farebot.card.desfire.RecordDesfireFileSettings.java
RecordDesfireFileSettings(ByteArrayInputStream stream) { super(stream); byte[] buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf);//from www . ja v a 2 s. c o m mRecordSize = Utils.byteArrayToInt(buf); buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); mMaxRecords = Utils.byteArrayToInt(buf); buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); mCurRecords = Utils.byteArrayToInt(buf); }
From source file:org.apache.oodt.product.handlers.ofsn.MD5GetHandler.java
public byte[] retrieveChunk(String filepath, long offset, int length) throws ProductException { try {// w w w .j a v a 2s . com String hash = this.hashData(FileUtils.readFileToByteArray(new File(filepath))); byte[] retBytes = new byte[length]; byte[] hashBytes = hash.getBytes(); ByteArrayInputStream is = new ByteArrayInputStream(hashBytes); is.skip(offset); is.read(retBytes, 0, length); return retBytes; } catch (IOException e) { LOG.log(Level.SEVERE, e.getMessage()); throw new ProductException( "Error reading bytes from file: [" + filepath + "] MD5: Message: " + e.getMessage()); } }
From source file:com.codebutler.farebot.card.desfire.settings.ValueDesfireFileSettings.java
public ValueDesfireFileSettings(ByteArrayInputStream stream) { super(stream); byte[] buf = new byte[4]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf);//from w ww.j av a2 s .co m mLowerLimit = Utils.byteArrayToInt(buf); buf = new byte[4]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); mUpperLimit = Utils.byteArrayToInt(buf); buf = new byte[4]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); mLimitedCreditValue = Utils.byteArrayToInt(buf); buf = new byte[1]; stream.read(buf, 0, buf.length); mLimitedCreditEnabled = buf[0] != 0x00; }
From source file:com.codebutler.farebot.card.desfire.raw.RawDesfireFileSettings.java
@NonNull private StandardDesfireFileSettings createStandardDesfireFileSettings(byte fileType, byte commSetting, byte[] accessRights, ByteArrayInputStream stream) { byte[] buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf);//from w w w . j a va 2s. c o m int fileSize = ByteUtils.byteArrayToInt(buf); return StandardDesfireFileSettings.create(fileType, commSetting, accessRights, fileSize); }
From source file:com.codebutler.farebot.card.desfire.raw.RawDesfireFileSettings.java
@NonNull private RecordDesfireFileSettings createRecordDesfireFileSettings(byte fileType, byte commSetting, byte[] accessRights, ByteArrayInputStream stream) { byte[] buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf);/*from w w w.j a va 2 s. c om*/ int recordSize = ByteUtils.byteArrayToInt(buf); buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); int maxRecords = ByteUtils.byteArrayToInt(buf); buf = new byte[3]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); int curRecords = ByteUtils.byteArrayToInt(buf); return RecordDesfireFileSettings.create(fileType, commSetting, accessRights, recordSize, maxRecords, curRecords); }
From source file:com.codebutler.farebot.card.desfire.raw.RawDesfireFileSettings.java
@NonNull private ValueDesfireFileSettings createValueDesfireFileSettings(byte fileType, byte commSetting, byte[] accessRights, ByteArrayInputStream stream) { byte[] buf = new byte[4]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf);/*from w w w . java 2 s .co m*/ int lowerLimit = ByteUtils.byteArrayToInt(buf); buf = new byte[4]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); int upperLimit = ByteUtils.byteArrayToInt(buf); buf = new byte[4]; stream.read(buf, 0, buf.length); ArrayUtils.reverse(buf); int limitedCreditValue = ByteUtils.byteArrayToInt(buf); buf = new byte[1]; stream.read(buf, 0, buf.length); boolean limitedCreditEnabled = buf[0] != 0x00; return ValueDesfireFileSettings.create(fileType, commSetting, accessRights, lowerLimit, upperLimit, limitedCreditValue, limitedCreditEnabled); }
From source file:org.ringside.client.BaseRequestHandler.java
protected CharSequence md5(CharSequence str) { try {//from www . ja v a2 s. c o m MessageDigest md = MessageDigest.getInstance("MD5"); ByteArrayInputStream bais = new ByteArrayInputStream(str.toString().getBytes()); byte[] bytes = new byte[1024]; int len; while ((len = bais.read(bytes, 0, bytes.length)) != -1) { md.update(bytes, 0, len); } bytes = md.digest(); StringBuffer sb = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { int hi = (bytes[i] >> 4) & 0xf; int lo = bytes[i] & 0xf; sb.append(Character.forDigit(hi, 16)); sb.append(Character.forDigit(lo, 16)); } return sb.toString(); } catch (Exception e) { LOG.error("Failed to generate MD5", e); return ""; } }