JUnit Assertion to verify a {@link java.io.InputStream} instance for accessibility.

@param inputStream {@link java.io.InputStream} instance
@param testable    rule(s) to apply
774798
public static void assertAccessibility(InputStream inputStream, Testable testable) {
        assertThat(inputStream, is(compliantTo(testable)));
    }
628345
public static Experiment readExperiment(final InputStream inputStream) throws IOException {
        checkNotNull(inputStream);
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            return readExperiment(reader);
        }
    }
1335855
@Override
  public boolean verifyMessage(InputStream publicKeyOfSender, InputStream message, InputStream signatureStream) {
    LOGGER.trace("verifyMessage(InputStream, InputStream, InputStream)");
    LOGGER.trace("Public Key: {}, Data: {}, Signature: {}",
        publicKeyOfSender == null ? "not set" : "set", message == null ? "not set" : "set", signatureStream == null ? "not set" : "set");
    boolean result = false;
    LOGGER.debug("Wrapping signature stream in ArmoredInputStream");
    try( InputStream armordPublicKeyStream = new ArmoredInputStream(signatureStream) ) {
      Object pgpObject;
      PGPObjectFactory pgpObjectFactory = new PGPObjectFactory(armordPublicKeyStream, new BcKeyFingerprintCalculator());
      LOGGER.debug("Iterating over PGP objects in stream");
      while( (pgpObject = pgpObjectFactory.nextObject()) != null ) {
        if( pgpObject instanceof PGPSignatureList ) {
          LOGGER.debug("Signature List found");
          PGPSignatureList signatureList = (PGPSignatureList)pgpObject;
          LOGGER.debug("Iterating over signature list");
          Iterator<PGPSignature> signatureIterator = signatureList.iterator();
          while( signatureIterator.hasNext() ) {
            LOGGER.debug("Checking next signature");
            final PGPSignature signature = signatureIterator.next();
            PGPPublicKey pgpPublicKey = findPublicKey(publicKeyOfSender, new KeyFilter<PGPPublicKey>() {
              @Override
              public boolean accept(PGPPublicKey pgpKey) {
                return pgpKey.getKeyID() == signature.getKeyID();
              }
            });
            if( pgpPublicKey != null ) {
              signature.init(new BcPGPContentVerifierBuilderProvider(), pgpPublicKey);
              LOGGER.debug("Processing signature data");
              IOUtils.process(message, new IOUtils.StreamHandler() {
                @Override
                public void handleStreamBuffer(byte[] buffer, int offset, int length) throws IOException {
                  signature.update(buffer, offset, length);
                }
              });
              result = signature.verify();
              LOGGER.info("Verify Signature: {}", result);
            } else {
              LOGGER.warn("No public key found for signature. Key ID: {}", signature.getKeyID());
            }
          }
        }
      }
    } catch (IOException | PGPException e) {
      LOGGER.error("{}", e.getMessage());
      result &= false;
    }
    return result;
  }
1274000
public static Sample readSample(final InputStream inputStream) throws IOException {
        checkNotNull(inputStream);
        try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {
            return readSample(reader);
        }
    }
975478
protected static void assertion(boolean b, String msg)
  {
  	if(!b)
  	{
  		throw new RuntimeException(XSLMessages.createMessage(XSLTErrorResources.ER_ASSERT_REDUNDENT_EXPR_ELIMINATOR, new Object[]{msg}));
  		// "Programmer's assertion in RundundentExprEliminator: "+msg);
  	}
  }
217589
public void release(InputStream inputStream) throws IOException {
    // for non-seekable input stream, close and return
    if (!(inputStream instanceof CachedSeekableInputStream) || !CACHE_ENABLED) {
      inputStream.close();
      return;
    }

    synchronized (mFileIdToInputStreamIds) {
      if (!mFileIdToInputStreamIds
          .containsKey(((CachedSeekableInputStream) inputStream).getFileId())) {
        LOG.debug("The resource {} is already expired",
            ((CachedSeekableInputStream) inputStream).getResourceId());
        // the cache no longer tracks this input stream
        inputStream.close();
        return;
      }
      UfsInputStreamIdSet resources =
          mFileIdToInputStreamIds.get(((CachedSeekableInputStream) inputStream).getFileId());
      if (!resources.release(((CachedSeekableInputStream) inputStream).getResourceId())) {
        LOG.debug("Close the expired input stream resource of {}",
            ((CachedSeekableInputStream) inputStream).getResourceId());
        // the input stream expired, close it
        inputStream.close();
      }
    }
  }
562338
@Override
    public int checkAbleToAcceptMessage(JsDestinationAddress addr)
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.entry(tc, "checkAbleToAcceptMessage", addr);

        int blockingReason = DestinationHandler.OUTPUT_HANDLER_FOUND;
        //we check the remoteQueueHighLimit in this case. 
        //See defect 281311
        boolean canAccept = !_itemStream.isRemoteQueueHighLimit();

        if (!canAccept)
        {
            blockingReason = DestinationHandler.OUTPUT_HANDLER_ALL_HIGH_LIMIT;
            //117505
            long destHighMsg = _itemStream.getDestHighMsgs();
            SibTr.info(tc, "NOTIFY_DEPTH_THRESHOLD_REACHED_CWSIP0553",
                       new Object[] { _destination.getName(), _messageProcessor.getMessagingEngineName(), destHighMsg });
        }
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            SibTr.exit(tc, "checkAbleToAcceptMessage", Integer.valueOf(blockingReason));
        return blockingReason;
    }
11211
void assertParent(Collection<Class<? extends Element>> permittedParents) throws InvalidInputException {
    if (!permittedParents.contains(this.getParent().getClass())) {
      throw new InvalidInputException("Element \"" + this.getMessageMLTag() + "\" is not allowed as a child of \""
          + this.getParent().getMessageMLTag() + "\"");
    }
  }
217714
public static IntStream ofNullable(int[] nullable) {
        return null == nullable ? IntStream.empty() : Arrays.stream(nullable);
    }
960134
@Override
    public void writeByteStream(InputStream is)
        throws IOException
    {
        while (true) {
            int len = SIZE - _offset - 3;

            if (len < 16) {
                flushBuffer();
                len = SIZE - _offset - 3;
            }

            len = is.read(_buffer, _offset + 3, len);

            if (len <= 0) {
                _buffer[_offset++] = BC_BINARY_DIRECT;
                return;
            }

            _buffer[_offset + 0] = (byte) BC_BINARY_CHUNK;
            _buffer[_offset + 1] = (byte) (len >> 8);
            _buffer[_offset + 2] = (byte) (len);

            _offset += len + 3;
        }
    }
1039684
@Override
	public List<GigJavaProblem> validate(TypeDeclaration declaration,
			IType type, CompilationUnit unit, String file)
			throws JavaModelException {
		List<GigJavaProblem> problems = new ArrayList<GigJavaProblem>();
		int flags = type.getFlags();
		
		if (!Flags.isAbstract(flags)) {
			if (!Flags.isPublic(flags)) {
				GigJavaProblem problem = new GigJavaProblem(
						Severity.ERROR, "Concrete Component class must be public", file);
				ISourceRange range = type.getNameRange();
				int offset = range.getOffset();
				problem.setSourceStart(offset);
				problem.setSourceEnd(offset + range.getLength() - 1);
				problem.setSourceLineNumber(unit.getLineNumber(offset));
				problems.add(problem);
				return problems;
			}
		}
		
		return problems;
	}
175570
protected boolean isAvailable(URL url) {

        try (InputStream inputStream = url.openStream()) {
            return true;
        } catch (IOException e) { //NOSONAR
            LOG.debug("URL {} not available", url, e);
            return false;
        }
    }
230005
SignerInfo verify(PKCS7 block, InputStream inputStream)
    throws NoSuchAlgorithmException, SignatureException, IOException {

       try {

            ContentInfo content = block.getContentInfo();
            if (inputStream == null) {
                inputStream = new ByteArrayInputStream(content.getContentBytes());
            }

            String digestAlgname = getDigestAlgorithmId().getName();

            InputStream dataSigned;

            // if there are authenticate attributes, get the message
            // digest and compare it with the digest of data
            if (authenticatedAttributes == null) {
                dataSigned = inputStream;
            } else {

                // first, check content type
                ObjectIdentifier contentType = (ObjectIdentifier)
                       authenticatedAttributes.getAttributeValue(
                         PKCS9Attribute.CONTENT_TYPE_OID);
                if (contentType == null ||
                    !contentType.equals(content.contentType))
                    return null;  // contentType does not match, bad SignerInfo

                // now, check message digest
                byte[] messageDigest = (byte[])
                    authenticatedAttributes.getAttributeValue(
                         PKCS9Attribute.MESSAGE_DIGEST_OID);

                if (messageDigest == null) // fail if there is no message digest
                    return null;

                MessageDigest md = MessageDigest.getInstance(
                        convertToStandardName(digestAlgname));

                byte[] buffer = new byte[4096];
                int read = 0;
                while ((read = inputStream.read(buffer)) != -1) {
                  md.update(buffer, 0 , read);
                }
                byte[] computedMessageDigest = md.digest();

                if (messageDigest.length != computedMessageDigest.length)
                    return null;
                for (int i = 0; i < messageDigest.length; i++) {
                    if (messageDigest[i] != computedMessageDigest[i])
                        return null;
                }

                // message digest attribute matched
                // digest of original data

                // the data actually signed is the DER encoding of
                // the authenticated attributes (tagged with
                // the "SET OF" tag, not 0xA0).
                dataSigned = new ByteArrayInputStream(authenticatedAttributes.getDerEncoding());
            }

            // put together digest algorithm and encryption algorithm
            // to form signing algorithm
            String encryptionAlgname =
                getDigestEncryptionAlgorithmId().getName();

            // Workaround: sometimes the encryptionAlgname is actually
            // a signature name
            String tmp = AlgorithmId.getEncAlgFromSigAlg(encryptionAlgname);
            if (tmp != null) encryptionAlgname = tmp;
            String algname = AlgorithmId.makeSigAlg(
                    digestAlgname, encryptionAlgname);

            Signature sig = Signature.getInstance(algname);
            X509Certificate cert = getCertificate(block);

            if (cert == null) {
                return null;
            }
            if (cert.hasUnsupportedCriticalExtension()) {
                throw new SignatureException("Certificate has unsupported "
                                             + "critical extension(s)");
            }

            // Make sure that if the usage of the key in the certificate is
            // restricted, it can be used for digital signatures.
            // XXX We may want to check for additional extensions in the
            // future.
            boolean[] keyUsageBits = cert.getKeyUsage();
            if (keyUsageBits != null) {
                KeyUsageExtension keyUsage;
                try {
                    // We don't care whether or not this extension was marked
                    // critical in the certificate.
                    // We're interested only in its value (i.e., the bits set)
                    // and treat the extension as critical.
                    keyUsage = new KeyUsageExtension(keyUsageBits);
                } catch (IOException ioe) {
                    throw new SignatureException("Failed to parse keyUsage "
                                                 + "extension");
                }

                boolean digSigAllowed = ((Boolean)keyUsage.get(
                        KeyUsageExtension.DIGITAL_SIGNATURE)).booleanValue();

                boolean nonRepuAllowed = ((Boolean)keyUsage.get(
                        KeyUsageExtension.NON_REPUDIATION)).booleanValue();

                if (!digSigAllowed && !nonRepuAllowed) {
                    throw new SignatureException("Key usage restricted: "
                                                 + "cannot be used for "
                                                 + "digital signatures");
                }
            }

            PublicKey key = cert.getPublicKey();
            sig.initVerify(key);

            byte[] buffer = new byte[4096];
            int read = 0;
            while ((read = dataSigned.read(buffer)) != -1) {
              sig.update(buffer, 0 , read);
            }
            if (sig.verify(encryptedDigest)) {
                return this;
            }

        } catch (IOException e) {
            throw new SignatureException("IO error verifying signature:\n" +
                                         e.getMessage());

        } catch (InvalidKeyException e) {
            throw new SignatureException("InvalidKey: " + e.getMessage());

        }
        return null;
    }
356526
public void init(final InputStream inputStream) {
		try (final InputStream is = inputStream) {
			final Manifest mf = new Manifest(is);
			final Attributes attr = mf.getMainAttributes();
			commit = attr.getValue("git-commit");
			gitUrl = attr.getValue("git-url");
			version = attr.getValue("project-version");
			final long time = Long.parseLong(attr.getValue("creation-date"));
			creationDate = DateFormat.getDateTimeInstance(DATEFORMAT, DATEFORMAT).format(new Date(time));
		} catch (Exception e) {
			initBackToDefaults();
		}
	}
642771
public void assertValidControllable() throws SIMPControllableNotFoundException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "assertValidControllable");

    if(streamSet == null || tsm == null)
    {
      SIMPControllableNotFoundException finalE =
        new SIMPControllableNotFoundException(
          nls.getFormattedMessage(
            "INTERNAL_MESSAGING_ERROR_CWSIP0002",
            new Object[] {"TargetStreamSetControl.assertValidControllable",
                "1:325:1.16",
                          streamID},
            null));

      SibTr.exception(tc, finalE);
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled()) 
        SibTr.exit(tc, "assertValidControllable", finalE);
      throw finalE;
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "assertValidControllable");
  }
310465
public void assertValidControllable() throws SIMPControllableNotFoundException
  {
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.entry(tc, "assertValidControllable");
      
    if(aoStream.itemStream == null || tick < 0 )
    {
      SIMPControllableNotFoundException finalE =
        new SIMPControllableNotFoundException(
          nls.getFormattedMessage(
            "INTERNAL_MESSAGING_ERROR_CWSIP0005",
            new Object[] {"QueuedMessage.assertValidControllable",
                          "1:416:1.48",
                          new Long(aoStream.getID())},
            null));
  
      SibTr.exception(tc, finalE);
      if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
        SibTr.exit(tc, "assertValidControllable");
      throw finalE;
    }
    
    if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
      SibTr.exit(tc, "assertValidControllable");
    
  }
415096
private void init(InputStream inputStream) {
        this.inputStream = inputStream;
        currentPath = new LinkedList<Node>();
        nodeQueue = new LinkedList<XmlNode>();
        XMLInputFactory factory = XMLInputFactory.newInstance();
        factory.setProperty("javax.xml.stream.isCoalescing", true);
        factory.setProperty("javax.xml.stream.isReplacingEntityReferences", true);
        try {
            reader = factory.createXMLStreamReader(inputStream);
        } catch (XMLStreamException e) {
            throw new XmlReaderException(e);
        }
    }