Java Code Examples for com.helger.commons.io.IHasInputStream#getInputStream()

The following examples show how to use com.helger.commons.io.IHasInputStream#getInputStream() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ISettingsPersistence.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Read settings from an InputStream provider and convert it to an
 * {@link ISettings} object.
 *
 * @param aISP
 *        The InputStream provider to read from. May not be <code>null</code>.
 * @return <code>null</code> if reading failed, a non-<code>null</code>
 *         settings object otherwise.
 */
@Nonnull
default ISettings readSettings (@Nonnull final IHasInputStream aISP)
{
  ValueEnforcer.notNull (aISP, "InputStreamProvider");

  final InputStream aIS = aISP.getInputStream ();
  if (aIS == null)
    throw new IllegalArgumentException ("Failed to open the provided input stream for the settings: " + aISP);
  return readSettings (aIS);
}
 
Example 2
Source File: JsonReader.java    From ph-commons with Apache License 2.0 5 votes vote down vote up
/**
 * Use an InputStream provider as JSON source with a custom fallback
 * charset.
 *
 * @param aISP
 *        The InputStream provider to be used. May not be <code>null</code>.
 * @param aFallbackCharset
 *        The fallback charset to be used. May not be <code>null</code>.
 * @return this for chaining
 */
@Nonnull
public Builder setSource (@Nonnull final IHasInputStream aISP, @Nonnull final Charset aFallbackCharset)
{
  ValueEnforcer.notNull (aISP, "InputStreamProvider");
  ValueEnforcer.notNull (aFallbackCharset, "FallbackCharset");

  final InputStream aIS = aISP.getInputStream ();
  if (aIS != null)
    setSource (aIS, aFallbackCharset);
  return this;
}
 
Example 3
Source File: CachingTransformStreamSource.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public CachingTransformStreamSource (@Nonnull final IHasInputStream aIIS, @Nullable final String sSystemID)
{
  this (aIIS.getInputStream (), sSystemID);
}
 
Example 4
Source File: CachingSAXInputSource.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public CachingSAXInputSource (@Nonnull final IHasInputStream aISP)
{
  this (aISP.getInputStream (), null);
}
 
Example 5
Source File: CachingSAXInputSource.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
public CachingSAXInputSource (@Nonnull final IHasInputStream aISP, @Nullable final String sSystemID)
{
  this (aISP.getInputStream (), sSystemID);
}
 
Example 6
Source File: JsonReader.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
/**
 * Check if the passed input stream can be resembled to valid Json content.
 * This is accomplished by fully parsing the Json file each time the method is
 * called. This consumes <b>less memory</b> than calling any of the
 * <code>read...</code> methods and checking for a non-<code>null</code>
 * result.
 *
 * @param aISP
 *        The resource to be parsed. May not be <code>null</code>.
 * @param aFallbackCharset
 *        The charset to be used for reading the Json file in case no BOM is
 *        present. May not be <code>null</code>.
 * @return <code>true</code> if the file can be parsed without error,
 *         <code>false</code> if not
 * @deprecated Since v9.3.3 - use {@link #builder()} instead.
 */
@Deprecated
public static boolean isValidJson (@Nonnull final IHasInputStream aISP, @Nonnull final Charset aFallbackCharset)
{
  ValueEnforcer.notNull (aISP, "InputStreamProvider");
  ValueEnforcer.notNull (aFallbackCharset, "FallbackCharset");

  final InputStream aIS = aISP.getInputStream ();
  if (aIS == null)
  {
    if (LOGGER.isWarnEnabled ())
      LOGGER.warn ("Failed to open Json InputStream from " + aISP);
    return false;
  }
  return isValidJson (aIS, aFallbackCharset);
}
 
Example 7
Source File: CSSReaderDeclarationList.java    From ph-css with Apache License 2.0 4 votes vote down vote up
/**
 * Read the CSS from the passed {@link IHasInputStream}.
 *
 * @param aISP
 *        The input stream provider to use. May not be <code>null</code>.
 * @param aCharset
 *        The charset to be used. May not be <code>null</code>.
 * @param eVersion
 *        The CSS version to use. May not be <code>null</code>.
 * @param aCustomErrorHandler
 *        An optional custom error handler that can be used to collect the
 *        recoverable parsing errors. May be <code>null</code>.
 * @param aCustomExceptionHandler
 *        An optional custom exception handler that can be used to collect the
 *        unrecoverable parsing errors. May be <code>null</code>.
 * @return <code>null</code> if reading failed, the CSS declarations
 *         otherwise.
 */
@Nullable
public static CSSDeclarationList readFromStream (@Nonnull final IHasInputStream aISP,
                                                 @Nonnull final Charset aCharset,
                                                 @Nonnull final ECSSVersion eVersion,
                                                 @Nullable final ICSSParseErrorHandler aCustomErrorHandler,
                                                 @Nullable final ICSSParseExceptionCallback aCustomExceptionHandler)
{
  ValueEnforcer.notNull (aISP, "InputStreamProvider");

  final InputStream aIS = aISP.getInputStream ();
  if (aIS == null)
    return null;
  return readFromReader (StreamHelper.createReader (aIS, aCharset),
                         new CSSReaderSettings ().setCSSVersion (eVersion)
                                                 .setCustomErrorHandler (aCustomErrorHandler)
                                                 .setCustomExceptionHandler (aCustomExceptionHandler));
}