List of usage examples for java.io DataInputStream readBoolean
public final boolean readBoolean() throws IOException
readBoolean
method of DataInput
. From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>NodePropBundle</code> from a data input stream. * * @param in the input stream//w w w. j a v a 2s. c om * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkBundle(DataInputStream in) { int version; // primaryType & version try { // read version and primary type...special handling int index = in.readInt(); // get version version = (index >> 24) & 0xff; index &= 0x00ffffff; String uri = nsIndex.indexToString(index); String local = nameIndex.indexToString(in.readInt()); Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local); log.debug("Serialzation Version: " + version); log.debug("NodeTypeName: " + nodeTypeName); } catch (IOException e) { log.error("Error while reading NodeTypeName: " + e); return false; } try { NodeId parentId = readID(in); log.debug("ParentUUID: " + parentId); } catch (IOException e) { log.error("Error while reading ParentUUID: " + e); return false; } try { String definitionId = in.readUTF(); log.debug("DefinitionId: " + definitionId); } catch (IOException e) { log.error("Error while reading DefinitionId: " + e); return false; } try { Name mixinName = readIndexedQName(in); while (mixinName != null) { log.debug("MixinTypeName: " + mixinName); mixinName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading MixinTypes: " + e); return false; } try { Name propName = readIndexedQName(in); while (propName != null) { log.debug("PropertyName: " + propName); if (!checkPropertyState(in)) { return false; } propName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading property names: " + e); return false; } try { boolean hasUUID = in.readBoolean(); log.debug("hasUUID: " + hasUUID); } catch (IOException e) { log.error("Error while reading 'hasUUID': " + e); return false; } try { NodeId cneId = readID(in); while (cneId != null) { Name cneName = readQName(in); log.debug("ChildNodentry: " + cneId + ":" + cneName); cneId = readID(in); } } catch (IOException e) { log.error("Error while reading child node entry: " + e); return false; } if (version >= VERSION_1) { try { short modCount = readModCount(in); log.debug("modCount: " + modCount); } catch (IOException e) { log.error("Error while reading mod cout: " + e); return false; } } return true; }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Checks a <code>NodePropBundle</code> from a data input stream. * * @param in the input stream//from w w w .j a v a 2 s . c o m * @return <code>true</code> if the data is valid; * <code>false</code> otherwise. */ public boolean checkBundle(DataInputStream in) { int version; // primaryType & version try { // read version and primary type...special handling int index = in.readInt(); // get version version = (index >> 24) & 0xff; index &= 0x00ffffff; String uri = nsIndex.indexToString(index); String local = nameIndex.indexToString(in.readInt()); Name nodeTypeName = NameFactoryImpl.getInstance().create(uri, local); log.debug("Serialzation Version: " + version); log.debug("NodeTypeName: " + nodeTypeName); } catch (IOException e) { log.error("Error while reading NodeTypeName: " + e); return false; } try { UUID parentUuid = readUUID(in); log.debug("ParentUUID: " + parentUuid); } catch (IOException e) { log.error("Error while reading ParentUUID: " + e); return false; } try { String definitionId = in.readUTF(); log.debug("DefinitionId: " + definitionId); } catch (IOException e) { log.error("Error while reading DefinitionId: " + e); return false; } try { Name mixinName = readIndexedQName(in); while (mixinName != null) { log.debug("MixinTypeName: " + mixinName); mixinName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading MixinTypes: " + e); return false; } try { Name propName = readIndexedQName(in); while (propName != null) { log.debug("PropertyName: " + propName); if (!checkPropertyState(in)) { return false; } propName = readIndexedQName(in); } } catch (IOException e) { log.error("Error while reading property names: " + e); return false; } try { boolean hasUUID = in.readBoolean(); log.debug("hasUUID: " + hasUUID); } catch (IOException e) { log.error("Error while reading 'hasUUID': " + e); return false; } try { UUID cneUUID = readUUID(in); while (cneUUID != null) { Name cneName = readQName(in); log.debug("ChildNodentry: " + cneUUID + ":" + cneName); cneUUID = readUUID(in); } } catch (IOException e) { log.error("Error while reading child node entry: " + e); return false; } if (version >= VERSION_1) { try { short modCount = readModCount(in); log.debug("modCount: " + modCount); } catch (IOException e) { log.error("Error while reading mod cout: " + e); return false; } } return true; }
From source file:org.apache.geode.internal.cache.tier.sockets.HandShake.java
/** * Client-side handshake with a Server// w ww. jav a 2 s . c om */ public ServerQueueStatus handshakeWithServer(Connection conn, ServerLocation location, CommunicationMode communicationMode) throws IOException, AuthenticationRequiredException, AuthenticationFailedException, ServerRefusedConnectionException { try { ServerQueueStatus serverQStatus = null; Socket sock = conn.getSocket(); DataOutputStream dos = new DataOutputStream(sock.getOutputStream()); final InputStream in = sock.getInputStream(); DataInputStream dis = new DataInputStream(in); DistributedMember member = getIDForSocket(sock); // if running in a loner system, use the new port number in the ID to // help differentiate from other clients DM dm = ((InternalDistributedSystem) this.system).getDistributionManager(); InternalDistributedMember idm = dm.getDistributionManagerId(); synchronized (idm) { if (idm.getPort() == 0 && dm instanceof LonerDistributionManager) { int port = sock.getLocalPort(); ((LonerDistributionManager) dm).updateLonerPort(port); updateProxyID(dm.getDistributionManagerId()); } } if (communicationMode.isWAN()) { this.credentials = getCredentials(member); } byte intermediateAcceptanceCode = write(dos, dis, communicationMode, REPLY_OK, this.clientReadTimeout, null, this.credentials, member, false); String authInit = this.system.getProperties().getProperty(SECURITY_CLIENT_AUTH_INIT); if (!communicationMode.isWAN() && intermediateAcceptanceCode != REPLY_AUTH_NOT_REQUIRED && (authInit != null && authInit.length() != 0)) { location.compareAndSetRequiresCredentials(true); } // Read the acceptance code byte acceptanceCode = dis.readByte(); if (acceptanceCode == (byte) 21 && !(sock instanceof SSLSocket)) { // This is likely the case of server setup with SSL and client not using // SSL throw new AuthenticationRequiredException( LocalizedStrings.HandShake_SERVER_EXPECTING_SSL_CONNECTION.toLocalizedString()); } if (acceptanceCode == REPLY_SERVER_IS_LOCATOR) { throw new GemFireConfigException("Improperly configured client detected. " + "Server at " + location + " is actually a locator. Use addPoolLocator to configure locators."); } // Successful handshake for GATEWAY_TO_GATEWAY mode sets the peer version in connection if (communicationMode.isWAN() && !(acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_REQUIRED || acceptanceCode == REPLY_EXCEPTION_AUTHENTICATION_FAILED)) { short wanSiteVersion = Version.readOrdinal(dis); conn.setWanSiteVersion(wanSiteVersion); // establish a versioned stream for the other site, if necessary if (wanSiteVersion < Version.CURRENT_ORDINAL) { dis = new VersionedDataInputStream(dis, Version.fromOrdinalOrCurrent(wanSiteVersion)); } } // No need to check for return value since DataInputStream already throws // EOFException in case of EOF byte epType = dis.readByte(); int qSize = dis.readInt(); // Read the server member member = readServerMember(dis); serverQStatus = new ServerQueueStatus(epType, qSize, member); // Read the message (if any) readMessage(dis, dos, acceptanceCode, member); // Read delta-propagation property value from server. // [sumedh] Static variable below? Client can connect to different // DSes with different values of this. It shoule be a member variable. if (!communicationMode.isWAN() && currentClientVersion.compareTo(Version.GFE_61) >= 0) { deltaEnabledOnServer = dis.readBoolean(); } // validate that the remote side has a different distributed system id. if (communicationMode.isWAN() && Version.GFE_66.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_66) >= 0) { int remoteDistributedSystemId = in.read(); int localDistributedSystemId = ((InternalDistributedSystem) system).getDistributionManager() .getDistributedSystemId(); if (localDistributedSystemId >= 0 && localDistributedSystemId == remoteDistributedSystemId) { throw new GatewayConfigurationException( "Remote WAN site's distributed system id " + remoteDistributedSystemId + " matches this sites distributed system id " + localDistributedSystemId); } } // Read the PDX registry size from the remote size if (communicationMode.isWAN() && Version.GFE_80.compareTo(conn.getWanSiteVersion()) <= 0 && currentClientVersion.compareTo(Version.GFE_80) >= 0) { int remotePdxSize = dis.readInt(); serverQStatus.setPdxSize(remotePdxSize); } return serverQStatus; } catch (IOException ex) { CancelCriterion stopper = this.system.getCancelCriterion(); stopper.checkCancelInProgress(null); throw ex; } }
From source file:com.codename1.impl.android.AndroidImplementation.java
public static void firePendingPushes(final PushCallback c, final Context a) { try {// ww w .j a v a 2 s.c om if (c != null) { InputStream i = a.openFileInput("CN1$AndroidPendingNotifications"); if (i == null) { return; } DataInputStream is = new DataInputStream(i); int count = is.readByte(); for (int iter = 0; iter < count; iter++) { boolean hasType = is.readBoolean(); String actualType = null; if (hasType) { actualType = is.readUTF(); } final String t; final String b; final String category; final String image; if ("99".equals(actualType)) { // This was a rich push Map<String, String> vals = splitQuery(is.readUTF()); t = vals.get("type"); b = vals.get("body"); category = vals.get("category"); image = vals.get("image"); } else { t = actualType; b = is.readUTF(); category = null; image = null; } long s = is.readLong(); Display.getInstance().callSerially(new Runnable() { @Override public void run() { Display.getInstance().setProperty("pendingPush", "true"); Display.getInstance().setProperty("pushType", t); initPushContent(b, image, t, category, a); if (t != null && ("3".equals(t) || "6".equals(t))) { String[] a = b.split(";"); c.push(a[0]); c.push(a[1]); } else if (t != null && ("101".equals(t))) { c.push(b.substring(b.indexOf(" ") + 1)); } else { c.push(b); } Display.getInstance().setProperty("pendingPush", null); } }); } a.deleteFile("CN1$AndroidPendingNotifications"); } } catch (IOException err) { } }
From source file:com.codename1.impl.android.AndroidImplementation.java
public static String[] getPendingPush(String type, Context a) { InputStream i = null;/* ww w. j ava 2s. c o m*/ try { i = a.openFileInput("CN1$AndroidPendingNotifications"); if (i == null) { return null; } DataInputStream is = new DataInputStream(i); int count = is.readByte(); Vector v = new Vector<String>(); for (int iter = 0; iter < count; iter++) { boolean hasType = is.readBoolean(); String actualType = null; if (hasType) { actualType = is.readUTF(); } final String t; final String b; if ("99".equals(actualType)) { // This was a rich push Map<String, String> vals = splitQuery(is.readUTF()); t = vals.get("type"); b = vals.get("body"); //category = vals.get("category"); //image = vals.get("image"); } else { t = actualType; b = is.readUTF(); //category = null; //image = null; } long s = is.readLong(); if (t != null && ("3".equals(t) || "6".equals(t))) { String[] m = b.split(";"); v.add(m[0]); } else if (t != null && "4".equals(t)) { String[] m = b.split(";"); v.add(m[1]); } else if (t != null && "2".equals(t)) { continue; } else if (t != null && "101".equals(t)) { v.add(b.substring(b.indexOf(" ") + 1)); } else { v.add(b); } } String[] retVal = new String[v.size()]; for (int j = 0; j < retVal.length; j++) { retVal[j] = (String) v.get(j); } return retVal; } catch (Exception ex) { ex.printStackTrace(); } finally { try { if (i != null) { i.close(); } } catch (IOException ex) { } } return null; }