List of usage examples for java.io DataInputStream readFully
public final void readFully(byte b[]) throws IOException
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Deserializes a <code>PropertyState</code> from the data input stream. * * @param in the input stream/* w w w.j a v a 2 s.com*/ * @param id the property id for the new property entry * @return the property entry * @throws IOException if an I/O error occurs. */ public NodePropBundle.PropertyEntry readPropertyEntry(DataInputStream in, PropertyId id) throws IOException { NodePropBundle.PropertyEntry entry = new NodePropBundle.PropertyEntry(id); // type and modcount int type = in.readInt(); entry.setModCount((short) ((type >> 16) & 0x0ffff)); type &= 0x0ffff; entry.setType(type); // multiValued entry.setMultiValued(in.readBoolean()); // definitionId entry.setPropDefId(PropDefId.valueOf(in.readUTF())); // values int count = in.readInt(); // count InternalValue[] values = new InternalValue[count]; String[] blobIds = new String[count]; for (int i = 0; i < count; i++) { InternalValue val; switch (type) { case PropertyType.BINARY: int size = in.readInt(); if (size == BINARY_IN_DATA_STORE) { val = InternalValue.create(dataStore, in.readUTF()); } else if (size == BINARY_IN_BLOB_STORE) { blobIds[i] = in.readUTF(); try { if (blobStore instanceof ResourceBasedBLOBStore) { val = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobIds[i])); } else { val = InternalValue.create(blobStore.get(blobIds[i])); } } catch (IOException e) { if (errorHandling.ignoreMissingBlobs()) { log.warn("Ignoring error while reading blob-resource: " + e); val = InternalValue.create(new byte[0]); } else { throw e; } } catch (Exception e) { throw new IOException("Unable to create property value: " + e.toString()); } } else { // short values into memory byte[] data = new byte[size]; in.readFully(data); val = InternalValue.create(data); } break; case PropertyType.DOUBLE: val = InternalValue.create(in.readDouble()); break; case PropertyType.DECIMAL: val = InternalValue.create(readDecimal(in)); break; case PropertyType.LONG: val = InternalValue.create(in.readLong()); break; case PropertyType.BOOLEAN: val = InternalValue.create(in.readBoolean()); break; case PropertyType.NAME: val = InternalValue.create(readQName(in)); break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: val = InternalValue.create(readUUID(in)); break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len = in.readInt(); byte[] bytes = new byte[len]; in.readFully(bytes); val = InternalValue.valueOf(new String(bytes, "UTF-8"), type); } values[i] = val; } entry.setValues(values); entry.setBlobIds(blobIds); return entry; }
From source file:VASSAL.tools.imports.adc2.MapBoard.java
/** * Read and set the order of the drawn element types. *//* w w w. j a v a 2 s .c o m*/ protected void readMapItemDrawingOrderBlock(DataInputStream in) throws IOException { ADC2Utils.readBlockHeader(in, "Map Item Drawing Order"); byte[] priority = new byte[10]; in.readFully(priority); ArrayList<MapLayer> items = new ArrayList<MapLayer>(mapElements.size()); for (int i = 0; i < mapElements.size(); ++i) { // invalid index: abort reordering and switch back to default if (priority[i] >= mapElements.size() || priority[i] < 0) return; if (i > 0) { // abort reordering and switch back to default if any indeces are repeated for (int j = 0; j < i; ++j) { if (priority[j] == priority[i]) return; } } items.add(mapElements.get(priority[i])); } // find out where it moved for (int i = 0; i < mapElements.size(); ++i) { drawingPriorities[priority[i]] = (byte) i; } // swap default order with specified order mapElements = items; }
From source file:org.opensc.pkcs15.token.impl.CardOSToken.java
private DF selectDFInternal(CommandAPDU cmd, TokenPath targetPath) throws IOException { try {// ww w .j av a 2 s .co m ResponseAPDU resp = this.channel.transmit(cmd); DataInputStream dis = getSelectFileData(resp); long bodySize = 0; int acLifeCycle = TokenFileAcl.AC_ALWAYS; int acUpdate = TokenFileAcl.AC_ALWAYS; int acAppend = TokenFileAcl.AC_ALWAYS; int acDeactivate = TokenFileAcl.AC_ALWAYS; int acActivate = TokenFileAcl.AC_ALWAYS; int acDelete = TokenFileAcl.AC_ALWAYS; int acAdmin = TokenFileAcl.AC_ALWAYS; int acCreate = TokenFileAcl.AC_ALWAYS; int tag; while ((tag = dis.read()) >= 0) { int n = dis.read(); if (n < 0) break; switch (tag) { case 0x81: if (n != 2) throw new IOException("Invalid length [" + n + "] of FCI tag 0x81."); bodySize = dis.readUnsignedShort(); break; case 0x83: if (n != 2) throw new IOException("Invalid length [" + n + "] of FCI tag 0x83."); int tpath = dis.readUnsignedShort(); if (tpath != targetPath.getTailID()) throw new IOException("File ID [" + PathHelper.formatID(tpath) + "] reported by SELECT FILE differs from requested ID [" + PathHelper.formatID(targetPath.getTailID()) + "]."); break; case 0x86: if (n >= 1) acLifeCycle = dis.read(); if (n >= 2) acUpdate = dis.read(); if (n >= 3) acAppend = dis.read(); if (n >= 4) acDeactivate = dis.read(); if (n >= 5) acActivate = dis.read(); if (n >= 6) acDelete = dis.read(); if (n >= 7) acAdmin = dis.read(); if (n >= 8) acCreate = dis.read(); if (n != 8) log.warn("Invalid length [" + n + "] of FCI tag 0x86 for DF."); if (n > 8) dis.skipBytes(n - 8); break; default: byte[] tmp = new byte[n]; dis.readFully(tmp); log.warn("skipping FCI tag [0x" + Integer.toHexString(tag) + "], data [" + Util.asHex(tmp) + "]."); } } DF df = new DF(targetPath, bodySize, acLifeCycle, acUpdate, acAppend, acDeactivate, acActivate, acDelete, acAdmin, acCreate); this.currentFile = df; return df; } catch (CardException e) { throw new PKCS15Exception("Error sending select MF", e); } }
From source file:android.core.SSLSocketTest.java
/** * Does a number of HTTPS requests on some host and consumes the response. * We don't use the HttpsUrlConnection class, but do this on our own * with the SSLSocket class. This gives us a chance to test the basic * behavior of SSL./*from w w w. ja v a 2s . c o m*/ * * @param host The host name the request is being sent to. * @param port The port the request is being sent to. * @param path The path being requested (e.g. "/index.html"). * @param outerLoop The number of times we reconnect and do the request. * @param innerLoop The number of times we do the request for each * connection (using HTTP keep-alive). * @param delay The delay after each request (in seconds). * @throws IOException When a problem occurs. */ private void fetch(SSLSocketFactory socketFactory, String host, int port, boolean secure, String path, int outerLoop, int innerLoop, int delay, int timeout) throws IOException { InetSocketAddress address = new InetSocketAddress(host, port); for (int i = 0; i < outerLoop; i++) { // Connect to the remote host Socket socket = secure ? socketFactory.createSocket() : new Socket(); if (timeout >= 0) { socket.setKeepAlive(true); socket.setSoTimeout(timeout * 1000); } socket.connect(address); // Get the streams OutputStream output = socket.getOutputStream(); PrintWriter writer = new PrintWriter(output); try { DataInputStream input = new DataInputStream(socket.getInputStream()); try { for (int j = 0; j < innerLoop; j++) { android.util.Log.d("SSLSocketTest", "GET https://" + host + path + " HTTP/1.1"); // Send a request writer.println("GET https://" + host + path + " HTTP/1.1\r"); writer.println("Host: " + host + "\r"); writer.println("Connection: " + (j == innerLoop - 1 ? "Close" : "Keep-Alive") + "\r"); writer.println("\r"); writer.flush(); int length = -1; boolean chunked = false; String line = input.readLine(); if (line == null) { throw new IOException("No response from server"); // android.util.Log.d("SSLSocketTest", "No response from server"); } // Consume the headers, check content length and encoding type while (line != null && line.length() != 0) { // System.out.println(line); int dot = line.indexOf(':'); if (dot != -1) { String key = line.substring(0, dot).trim(); String value = line.substring(dot + 1).trim(); if ("Content-Length".equalsIgnoreCase(key)) { length = Integer.valueOf(value); } else if ("Transfer-Encoding".equalsIgnoreCase(key)) { chunked = "Chunked".equalsIgnoreCase(value); } } line = input.readLine(); } assertTrue("Need either content length or chunked encoding", length != -1 || chunked); // Consume the content itself if (chunked) { length = Integer.parseInt(input.readLine(), 16); while (length != 0) { byte[] buffer = new byte[length]; input.readFully(buffer); input.readLine(); length = Integer.parseInt(input.readLine(), 16); } input.readLine(); } else { byte[] buffer = new byte[length]; input.readFully(buffer); } // Sleep for the given number of seconds try { Thread.sleep(delay * 1000); } catch (InterruptedException ex) { // Shut up! } } } finally { input.close(); } } finally { writer.close(); } // Close the connection socket.close(); } }
From source file:org.opensc.pkcs15.token.impl.CardOSToken.java
@Override public EF selectEF(int path) throws IOException { if (this.currentFile == null) throw new IOException("No current DF selected."); // SELECT FILE, P1=0x02, P2=0x00, no data -> select EF CommandAPDU cmd = new CommandAPDU(0x00, 0xA4, 0x02, 0x00, PathHelper.idToPath(path), DEFAULT_LE); try {// w w w. j av a 2 s.c om ResponseAPDU resp = this.channel.transmit(cmd); DataInputStream dis = getSelectFileData(resp); long fileSize = 0; int acRead = TokenFileAcl.AC_ALWAYS; int acUpdate = TokenFileAcl.AC_ALWAYS; int acAppend = TokenFileAcl.AC_ALWAYS; int acDeactivate = TokenFileAcl.AC_ALWAYS; int acActivate = TokenFileAcl.AC_ALWAYS; int acDelete = TokenFileAcl.AC_ALWAYS; int acAdmin = TokenFileAcl.AC_ALWAYS; int acIncrease = TokenFileAcl.AC_ALWAYS; int acDecrease = TokenFileAcl.AC_ALWAYS; int tag; while ((tag = dis.read()) >= 0) { int n = dis.read(); if (n < 0) break; switch (tag) { case 0x80: if (n != 2) throw new IOException("Invalid length [" + n + "] of FCI tag 0x80."); fileSize = dis.readUnsignedShort(); break; case 0x83: if (n != 2) throw new IOException("Invalid length [" + n + "] of FCI tag 0x83."); int tpath = dis.readUnsignedShort(); if (tpath != path) throw new IOException("File ID [" + PathHelper.formatID(tpath) + "] reported by SELECT FILE differs from requested ID [" + PathHelper.formatID(path) + "]."); break; case 0x86: if (n >= 1) acRead = dis.read(); if (n >= 2) acUpdate = dis.read(); if (n >= 3) acAppend = dis.read(); if (n >= 4) acDeactivate = dis.read(); if (n >= 5) acActivate = dis.read(); if (n >= 6) acDelete = dis.read(); if (n >= 7) acAdmin = dis.read(); if (n >= 8) acIncrease = dis.read(); if (n >= 9) acDecrease = dis.read(); if (n != 9) log.warn("Invalid length [" + n + "] of FCI tag 0x86 for EF."); if (n > 9) dis.skipBytes(n - 9); break; default: byte[] tmp = new byte[n]; dis.readFully(tmp); log.warn("skipping FCI tag [0x" + Integer.toHexString(tag) + "], data [" + Util.asHex(tmp) + "]."); } } EF ef = new EF(new TokenPath(this.currentFile.getPath(), path), fileSize, acRead, acUpdate, acAppend, acDeactivate, acActivate, acDelete, acAdmin, acIncrease, acDecrease); this.currentFile = ef; return ef; } catch (CardException e) { throw new PKCS15Exception("Error sending select MF", e); } }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>PropertyState</code> from the data input stream. * * @param in the input stream// w ww. java 2 s. c o m * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkPropertyState(DataInputStream in) { int type; try { type = in.readInt(); short modCount = (short) ((type >> 16) | 0xffff); type &= 0xffff; log.debug(" PropertyType: " + PropertyType.nameFromValue(type)); log.debug(" ModCount: " + modCount); } catch (IOException e) { log.error("Error while reading property type: " + e); return false; } try { boolean isMV = in.readBoolean(); log.debug(" MultiValued: " + isMV); } catch (IOException e) { log.error("Error while reading multivalued: " + e); return false; } try { String defintionId = in.readUTF(); log.debug(" DefinitionId: " + defintionId); } catch (IOException e) { log.error("Error while reading definition id: " + e); return false; } int count; try { count = in.readInt(); log.debug(" num values: " + count); } catch (IOException e) { log.error("Error while reading number of values: " + e); return false; } for (int i = 0; i < count; i++) { switch (type) { case PropertyType.BINARY: int size; try { size = in.readInt(); log.debug(" binary size: " + size); } catch (IOException e) { log.error("Error while reading size of binary: " + e); return false; } if (size == BINARY_IN_DATA_STORE) { try { String s = in.readUTF(); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" global data store id: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else if (size == BINARY_IN_BLOB_STORE) { try { String s = in.readUTF(); log.debug(" blobid: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else { // short values into memory byte[] data = new byte[size]; try { in.readFully(data); log.debug(" binary: " + data.length + " bytes"); } catch (IOException e) { log.error("Error while reading inlined binary: " + e); return false; } } break; case PropertyType.DOUBLE: try { double d = in.readDouble(); log.debug(" double: " + d); } catch (IOException e) { log.error("Error while reading double value: " + e); return false; } break; case PropertyType.LONG: try { double l = in.readLong(); log.debug(" long: " + l); } catch (IOException e) { log.error("Error while reading long value: " + e); return false; } break; case PropertyType.BOOLEAN: try { boolean b = in.readBoolean(); log.debug(" boolean: " + b); } catch (IOException e) { log.error("Error while reading boolean value: " + e); return false; } break; case PropertyType.NAME: try { Name name = readQName(in); log.debug(" name: " + name); } catch (IOException e) { log.error("Error while reading name value: " + e); return false; } break; case PropertyType.REFERENCE: try { UUID uuid = readUUID(in); log.debug(" reference: " + uuid); } catch (IOException e) { log.error("Error while reading reference value: " + e); return false; } break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len; try { len = in.readInt(); log.debug(" size of string value: " + len); } catch (IOException e) { log.error("Error while reading size of string value: " + e); return false; } try { byte[] bytes = new byte[len]; in.readFully(bytes); String s = new String(bytes, "UTF-8"); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" string: " + s); } catch (IOException e) { log.error("Error while reading string value: " + e); return false; } } } return true; }
From source file:VASSAL.tools.imports.adc2.MapBoard.java
@Override protected void load(File f) throws IOException { super.load(f); DataInputStream in = null; try {/*www . jav a 2 s .c om*/ in = new DataInputStream(new BufferedInputStream(new FileInputStream(f))); baseName = stripExtension(f.getName()); path = f.getPath(); int header = in.readByte(); if (header != -3) throw new FileFormatException("Invalid Mapboard File Header"); // don't know what these do. in.readFully(new byte[2]); // get the symbol set String s = readWindowsFileName(in); String symbolSetFileName = forceExtension(s, "set"); set = new SymbolSet(); File setFile = action.getCaseInsensitiveFile(new File(symbolSetFileName), f, true, new ExtensionFileFilter(ADC2Utils.SET_DESCRIPTION, new String[] { ADC2Utils.SET_EXTENSION })); if (setFile == null) throw new FileNotFoundException("Unable to find symbol set file."); set.importFile(action, setFile); in.readByte(); // ignored columns = ADC2Utils.readBase250Word(in); rows = ADC2Utils.readBase250Word(in); // presumably, they're all the same size (and they're square) int hexSize = set.getMapBoardSymbolSize(); // each block read separately readHexDataBlock(in); readPlaceNameBlock(in); readHexSideBlock(in); readLineDefinitionBlock(in); readAttributeBlock(in); readMapSheetBlock(in); readHexLineBlock(in); readLineDrawPriorityBlock(in); // end of data blocks int orientation = in.read(); switch (orientation) { case 0: case 1: // vertical hex orientation or grid offset column if (set.getMapBoardSymbolShape() == SymbolSet.Shape.SQUARE) layout = new GridOffsetColumnLayout(hexSize, columns, rows); else layout = new VerticalHexLayout(hexSize, columns, rows); break; case 2: // horizontal hex orientation or grid offset row if (set.getMapBoardSymbolShape() == SymbolSet.Shape.SQUARE) layout = new GridOffsetRowLayout(hexSize, columns, rows); else layout = new HorizontalHexLayout(hexSize, columns, rows); break; default: // square grid -- no offset layout = new GridLayout(hexSize, columns, rows); } /* int saveMapPosition = */ in.readByte(); /* int mapViewingPosition = */ in.readShort(); // probably base-250 /* int mapViewingZoomLevel = */ in.readShort(); in.readByte(); // totally unknown // strangely, more blocks readTableColorBlock(in); readHexNumberingBlock(in); // TODO: default map item drawing order appears to be different for different maps. try { // optional blocks readMapBoardOverlaySymbolBlock(in); readVersionBlock(in); readMapItemDrawingOrderBlock(in); readMapItemDrawFlagBlock(in); } catch (ADC2Utils.NoMoreBlocksException e) { } in.close(); } finally { IOUtils.closeQuietly(in); } }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>PropertyState</code> from the data input stream. * * @param in the input stream// w w w . j ava 2 s . c om * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkPropertyState(DataInputStream in) { int type; try { type = in.readInt(); short modCount = (short) ((type >> 16) | 0xffff); type &= 0xffff; log.debug(" PropertyType: " + PropertyType.nameFromValue(type)); log.debug(" ModCount: " + modCount); } catch (IOException e) { log.error("Error while reading property type: " + e); return false; } try { boolean isMV = in.readBoolean(); log.debug(" MultiValued: " + isMV); } catch (IOException e) { log.error("Error while reading multivalued: " + e); return false; } try { String defintionId = in.readUTF(); log.debug(" DefinitionId: " + defintionId); } catch (IOException e) { log.error("Error while reading definition id: " + e); return false; } int count; try { count = in.readInt(); log.debug(" num values: " + count); } catch (IOException e) { log.error("Error while reading number of values: " + e); return false; } for (int i = 0; i < count; i++) { switch (type) { case PropertyType.BINARY: int size; try { size = in.readInt(); log.debug(" binary size: " + size); } catch (IOException e) { log.error("Error while reading size of binary: " + e); return false; } if (size == BINARY_IN_DATA_STORE) { try { String s = in.readUTF(); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" global data store id: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else if (size == BINARY_IN_BLOB_STORE) { try { String s = in.readUTF(); log.debug(" blobid: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else { // short values into memory byte[] data = new byte[size]; try { in.readFully(data); log.debug(" binary: " + data.length + " bytes"); } catch (IOException e) { log.error("Error while reading inlined binary: " + e); return false; } } break; case PropertyType.DOUBLE: try { double d = in.readDouble(); log.debug(" double: " + d); } catch (IOException e) { log.error("Error while reading double value: " + e); return false; } break; case PropertyType.DECIMAL: try { BigDecimal d = readDecimal(in); log.debug(" decimal: " + d); } catch (IOException e) { log.error("Error while reading decimal value: " + e); return false; } break; case PropertyType.LONG: try { double l = in.readLong(); log.debug(" long: " + l); } catch (IOException e) { log.error("Error while reading long value: " + e); return false; } break; case PropertyType.BOOLEAN: try { boolean b = in.readBoolean(); log.debug(" boolean: " + b); } catch (IOException e) { log.error("Error while reading boolean value: " + e); return false; } break; case PropertyType.NAME: try { Name name = readQName(in); log.debug(" name: " + name); } catch (IOException e) { log.error("Error while reading name value: " + e); return false; } break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: try { NodeId id = readID(in); log.debug(" reference: " + id); } catch (IOException e) { log.error("Error while reading reference value: " + e); return false; } break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len; try { len = in.readInt(); log.debug(" size of string value: " + len); } catch (IOException e) { log.error("Error while reading size of string value: " + e); return false; } try { byte[] bytes = new byte[len]; in.readFully(bytes); String s = new String(bytes, "UTF-8"); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" string: " + s); } catch (IOException e) { log.error("Error while reading string value: " + e); return false; } } } return true; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>PropertyState</code> from the data input stream. * * @param in the input stream/*from www . jav a2 s . c om*/ * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkPropertyState(DataInputStream in) { int type; try { type = in.readInt(); short modCount = (short) ((type >> 16) | 0xffff); type &= 0xffff; log.debug(" PropertyType: " + PropertyType.nameFromValue(type)); log.debug(" ModCount: " + modCount); } catch (IOException e) { log.error("Error while reading property type: " + e); return false; } try { boolean isMV = in.readBoolean(); log.debug(" MultiValued: " + isMV); } catch (IOException e) { log.error("Error while reading multivalued: " + e); return false; } try { String defintionId = in.readUTF(); log.debug(" DefinitionId: " + defintionId); } catch (IOException e) { log.error("Error while reading definition id: " + e); return false; } int count; try { count = in.readInt(); log.debug(" num values: " + count); } catch (IOException e) { log.error("Error while reading number of values: " + e); return false; } for (int i = 0; i < count; i++) { switch (type) { case PropertyType.BINARY: int size; try { size = in.readInt(); log.debug(" binary size: " + size); } catch (IOException e) { log.error("Error while reading size of binary: " + e); return false; } if (size == BINARY_IN_DATA_STORE) { try { String s = in.readUTF(); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" global data store id: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else if (size == BINARY_IN_BLOB_STORE) { try { String s = in.readUTF(); log.debug(" blobid: " + s); } catch (IOException e) { log.error("Error while reading blob id: " + e); return false; } } else { // short values into memory byte[] data = new byte[size]; try { in.readFully(data); log.debug(" binary: " + data.length + " bytes"); } catch (IOException e) { log.error("Error while reading inlined binary: " + e); return false; } } break; case PropertyType.DOUBLE: try { double d = in.readDouble(); log.debug(" double: " + d); } catch (IOException e) { log.error("Error while reading double value: " + e); return false; } break; case PropertyType.DECIMAL: try { BigDecimal d = readDecimal(in); log.debug(" decimal: " + d); } catch (IOException e) { log.error("Error while reading decimal value: " + e); return false; } break; case PropertyType.LONG: try { double l = in.readLong(); log.debug(" long: " + l); } catch (IOException e) { log.error("Error while reading long value: " + e); return false; } break; case PropertyType.BOOLEAN: try { boolean b = in.readBoolean(); log.debug(" boolean: " + b); } catch (IOException e) { log.error("Error while reading boolean value: " + e); return false; } break; case PropertyType.NAME: try { Name name = readQName(in); log.debug(" name: " + name); } catch (IOException e) { log.error("Error while reading name value: " + e); return false; } break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: try { UUID uuid = readUUID(in); log.debug(" reference: " + uuid); } catch (IOException e) { log.error("Error while reading reference value: " + e); return false; } break; default: // because writeUTF(String) has a size limit of 64k, // Strings are serialized as <length><byte[]> int len; try { len = in.readInt(); log.debug(" size of string value: " + len); } catch (IOException e) { log.error("Error while reading size of string value: " + e); return false; } try { byte[] bytes = new byte[len]; in.readFully(bytes); String s = new String(bytes, "UTF-8"); // truncate log output if (s.length() > 80) { s = s.substring(80) + "..."; } log.debug(" string: " + s); } catch (IOException e) { log.error("Error while reading string value: " + e); return false; } } } return true; }
From source file:org.opensc.pkcs15.token.impl.CardOSToken.java
@Override public MF selectMF() throws IOException { // SELECT FILE, P1=0x00, P2=0x00, no data -> select MF CommandAPDU cmd = new CommandAPDU(0x00, 0xA4, 0x00, 0x00, DEFAULT_LE); try {/*from w ww. j a v a 2 s. c o m*/ ResponseAPDU resp = this.channel.transmit(cmd); DataInputStream dis = getSelectFileData(resp); long bodySize = 0; int acLifeCycle = TokenFileAcl.AC_ALWAYS; int acUpdate = TokenFileAcl.AC_ALWAYS; int acAppend = TokenFileAcl.AC_ALWAYS; int acDeactivate = TokenFileAcl.AC_ALWAYS; int acActivate = TokenFileAcl.AC_ALWAYS; int acDelete = TokenFileAcl.AC_ALWAYS; int acAdmin = TokenFileAcl.AC_ALWAYS; int acCreate = TokenFileAcl.AC_ALWAYS; int acExecute = TokenFileAcl.AC_ALWAYS; int acAllocate = TokenFileAcl.AC_ALWAYS; int tag; while ((tag = dis.read()) >= 0) { int n = dis.read(); if (n < 0) break; switch (tag) { case 0x81: if (n != 2) throw new IOException("Invalid length [" + n + "] of FCI tag 0x81."); bodySize = dis.readUnsignedShort(); break; case 0x83: if (n != 2) throw new IOException("Invalid length [" + n + "] of FCI tag 0x83."); int tpath = dis.readUnsignedShort(); if (tpath != PathHelper.MF_ID) throw new IOException("File ID [" + PathHelper.formatID(tpath) + "] reported by SELECT FILE differs from requested ID [" + PathHelper.formatID(PathHelper.MF_ID) + "]."); break; case 0x86: if (n >= 1) acLifeCycle = dis.read(); if (n >= 2) acUpdate = dis.read(); if (n >= 3) acAppend = dis.read(); if (n >= 4) acDeactivate = dis.read(); if (n >= 5) acActivate = dis.read(); if (n >= 6) acDelete = dis.read(); if (n >= 7) acAdmin = dis.read(); if (n >= 8) acCreate = dis.read(); if (n >= 9) acExecute = dis.read(); if (n >= 10) acAllocate = dis.read(); if (n != 10) log.warn("Invalid length [" + n + "] of FCI tag 0x86 for MF."); if (n > 10) dis.skipBytes(n - 10); break; default: byte[] tmp = new byte[n]; dis.readFully(tmp); log.warn("skipping FCI tag [0x" + Integer.toHexString(tag) + "], data [" + Util.asHex(tmp) + "]."); } } MF mf = new MF(PathHelper.MF_PATH, bodySize, acLifeCycle, acUpdate, acAppend, acDeactivate, acActivate, acDelete, acAdmin, acCreate, acExecute, acAllocate); this.currentFile = mf; return mf; } catch (CardException e) { throw new PKCS15Exception("Error sending select MF", e); } }