/** * Creates a new <code>OctetStreamData</code>. * * @param octetStream the input stream containing the octets * @throws NullPointerException if <code>octetStream</code> is * <code>null</code> */ public OctetStreamData(java.io.InputStream octetStream) { if (octetStream == null) { throw new java.lang.NullPointerException("octetStream is null"); } this.octetStream = octetStream; }
/** * Copies the ArchiveEntry to the Output stream * * @param in * the stream to read the data from * @param out * the stream to write the data to * @param entry * the entry to write * @throws IOException * if data cannot be read or written */ private void copyStream(java.io.InputStream inJ, ArchiveOutputStream outJ, ArchiveEntry entry) //throws IOException { outJ.putArchiveEntry(entry); IOUtils.copy(inJ, outJ); outJ.closeArchiveEntry(); }
/* * Constructs a new {@code Manifest} instance obtaining attribute * information from the specified input stream. * * @param is * The {@code InputStream} to read from. * @throws IOException * If an error occurs reading the {@code Manifest}. */ public void read(java.io.InputStream isJ) //throws IOException { { byte[] buf; // Try to read get a reference to the bytes directly try { buf = org.apache.harmony.luni.util.InputStreamHelper.expose(isJ); } catch (java.lang.UnsupportedOperationException uoe) { buf = readFully(isJ); } if (buf.Length == 0) { return; } // a workaround for HARMONY-5662 // replace EOF and NUL with another new line // which does not trigger an error byte b = buf[buf.Length - 1]; if (0 == b || 26 == b) { buf[buf.Length - 1] = (byte)'\n'; } // Attributes.Name.MANIFEST_VERSION is not used for // the second parameter for RI compatibility im = new InitManifest(buf, mainAttributes, null); mainEnd = im.getPos(); // FIXME im.initEntries(entries, chunks); im = null; }
/* * Reads all the bytes from the given input stream. * * Calls read multiple times on the given input stream until it receives an * end of file marker. Returns the combined results as a byte array. Note * that this method may block if the underlying stream read blocks. * * @param is * the input stream to be read. * @return the content of the stream as a byte array. * @throws IOException * if a read error occurs. */ public static byte[] readFullyAndClose(java.io.InputStream isJ) // throws IOException { { try { // Initial read byte[] buffer = new byte[1024]; int count = isJ.read(buffer); int nextByte = isJ.read(); // Did we get it all in one read? if (nextByte == -1) { byte[] dest = new byte[count]; java.lang.SystemJ.arraycopy(buffer, 0, dest, 0, count); return(dest); } // Requires additional reads java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(count * 2); baos.write(buffer, 0, count); baos.write(nextByte); while (true) { count = isJ.read(buffer); if (count == -1) { return(baos.toByteArray()); } baos.write(buffer, 0, count); } } finally { isJ.close(); } }
private void init(java.io.InputStream inStream, java.io.OutputStream outStream, int blockSize, int recordSize) { this.inStream = inStream; this.outStream = outStream; this.initialize(blockSize, recordSize); }
/** * This method returns an Inputstream for the reading resource * META_INF/services/org.w3c.dom.DOMImplementationSourceList after checking * access control privileges. For a JRE 1.1, this check is not done. * * @param classLoader classLoader * @param name the resource * @return an Inputstream for the resource specified */ private static java.io.InputStream getResourceAsStream(java.lang.ClassLoader classLoader, String name) { java.io.InputStream input = null == classLoader?java.lang.ClassLoader.getSystemResourceAsStream(name) : classLoader.getResourceAsStream(name); return(input); /* * if (isJRE11()) { * InputStream ris; * if (classLoader == null) { * ris = ClassLoader.getSystemResourceAsStream(name); * } else { * ris = classLoader.getResourceAsStream(name); * } * return ris; * } else { * return (InputStream) * AccessController.doPrivileged(new PrivilegedAction() { * public Object run() { * InputStream ris; * if (classLoader == null) { * ris = * ClassLoader.getSystemResourceAsStream(name); * } else { * ris = classLoader.getResourceAsStream(name); * } * return ris; * } * });*/ }
/** * Returns the {@code Manifest} object associated with this {@code JarFile} * or {@code null} if no MANIFEST entry exists. * * @return the MANIFEST. * @throws IOException * if an error occurs reading the MANIFEST file. * @throws IllegalStateException * if the jar file is closed. * @see Manifest */ public Manifest getManifest() // throws IOException { { if (closed) { // archive.35=JarFile has been closed throw new java.lang.IllegalStateException("JarFile has been closed"); //$NON-NLS-1$ } if (manifest != null) { return(manifest); } try { java.io.InputStream isJ = base.getInputStream(manifestEntry); if (verifier != null) { verifier.addMetaEntry(manifestEntry.getName(), org.apache.harmony.luni.util.InputStreamHelper.readFullyAndClose(isJ)); isJ = base.getInputStream(manifestEntry); } try { manifest = new Manifest(isJ, verifier != null); } finally { isJ.close(); } manifestEntry = null; // Can discard the entry now. } catch (java.lang.NullPointerException) { manifestEntry = null; } return(manifest); }
private int bsR(int n) //throws IOException { int bsLiveShadow = this.bsLive; int bsBuffShadow = this.bsBuff; if (bsLiveShadow < n) { java.io.InputStream inShadow = this.inJ; do { int thech = inShadow.read(); if (thech < 0) { throw new java.io.IOException("unexpected end of stream"); } bsBuffShadow = (bsBuffShadow << 8) | thech; bsLiveShadow += 8; } while (bsLiveShadow < n); this.bsBuff = bsBuffShadow; } this.bsLive = bsLiveShadow - n; return((bsBuffShadow >> (bsLiveShadow - n)) & ((1 << n) - 1)); }
/* * Constructs a new {@code ZipInputStream} from the specified input stream. * * @param stream * the input stream to representing a ZIP archive. */ public ZipInputStream(java.io.InputStream stream) : base(new java.io.PushbackInputStream(stream, BUF_SIZE), new Inflater(true)) { if (stream == null) { throw new java.lang.NullPointerException(); } }
/** * Create an compressor input stream from an input stream, autodetecting * the compressor type from the first few bytes of the stream. The InputStream * must support marks, like BufferedInputStream. * * @param in the input stream * @return the compressor input stream * @throws CompressorException if the compressor name is not known * @throws IllegalArgumentException if the stream is null or does not support mark * @since Commons Compress 1.1 */ public CompressorInputStream createCompressorInputStream(java.io.InputStream inJ) //throws CompressorException { if (inJ == null) { throw new java.lang.IllegalArgumentException("Stream must not be null."); } if (!inJ.markSupported()) { throw new java.lang.IllegalArgumentException("Mark is not supported."); } byte[] signature = new byte[12]; inJ.mark(signature.Length); try { int signatureLength = inJ.read(signature); inJ.reset(); if (BZip2CompressorInputStream.matches(signature, signatureLength)) { return(new BZip2CompressorInputStream(inJ)); } if (GzipCompressorInputStream.matches(signature, signatureLength)) { return(new GzipCompressorInputStream(inJ)); } } catch (java.io.IOException e) { throw new CompressorException("Failed to detect Compressor from InputStream.", e); } throw new CompressorException("No Compressor found for the stream signature."); }
/* * Reads SQL statements from System.in() and returns a * tsResultSet for the last statement executed. This is * really only good for testing. * * @exception TinySQLException */ public virtual TsResultSet sqlexec() {// throws TinySQLException { SQLStream = (java.io.InputStream)java.lang.SystemJ.inJ; java.lang.SystemJ.err.println("Reading SQL Statements from STDIN..."); java.lang.SystemJ.err.println("CRASHING AFTER THIS POINT IS SURE..."); java.lang.SystemJ.err.println("Have no Statement, no connection and no clue how to continue ..."); return(sql(null)); }
protected internal Manifest(java.io.InputStream isJ, bool readChunks) //throws IOException { { if (readChunks) { chunks = new HashMap <String, Chunk>(); } read(isJ); }
public Decode(SevenZip.Compression.LZMA.Decoder decoder, java.io.InputStream inputStream, java.io.OutputStream outputStream, long size) : base() { this.decoder = decoder; this.inputStream = inputStream; this.outputStream = outputStream; this.size = size; }
/* * This constructor lets you specify both the {@code Inflater} as well as * the internal buffer size to be used. * * @param is * the {@code InputStream} to read data from. * @param inf * the specific {@code Inflater} for uncompressing data. * @param bsize * the size to be used for the internal buffer. */ public InflaterInputStream(java.io.InputStream isJ, Inflater inf, int bsize) : base (isJ){ if (isJ == null || inf == null) { throw new java.lang.NullPointerException(); } if (bsize <= 0) { throw new java.lang.IllegalArgumentException(); } this.inf = inf; buf = new byte[bsize]; }
public ZInputStream(java.io.InputStream inJ, int level) : base(inJ) { buf = new byte[bufsize]; this.inJ = inJ; z.deflateInit(level); compress = true; z.next_in = buf; z.next_in_index = 0; z.avail_in = 0; }
public ZInputStream(java.io.InputStream inJ, bool nowrap) : base(inJ) { buf = new byte[bufsize]; this.inJ = inJ; z.inflateInit(nowrap); compress = false; z.next_in = buf; z.next_in_index = 0; z.avail_in = 0; }
/** * Creates a new <code>OctetStreamData</code>. * * @param octetStream the input stream containing the octets * @param uri the URI String identifying the data object (may be * <code>null</code>) * @param mimeType the MIME type associated with the data object (may be * <code>null</code>) * @throws NullPointerException if <code>octetStream</code> is * <code>null</code> */ public OctetStreamData(java.io.InputStream octetStream, String uri, String mimeType) { if (octetStream == null) { throw new java.lang.NullPointerException("octetStream is null"); } this.octetStream = octetStream; this.uri = uri; this.mimeType = mimeType; }
/* * Parse the content of the given <code>InputStream</code> as an XML * document and return a new DOM {@link Document} object. * An <code>IllegalArgumentException</code> is thrown if the * <code>InputStream</code> is null. * * @param is InputStream containing the content to be parsed. * @return <code>Document</code> result of parsing the * <code>InputStream</code> * @exception IOException If any IO errors occur. * @exception SAXException If any parse errors occur. * @see org.xml.sax.DocumentHandler */ public Document parse(java.io.InputStream isJ) { //throws SAXException, IOException { if (isJ == null) { throw new java.lang.IllegalArgumentException("InputStream cannot be null"); } InputSource inJ = new InputSource(isJ); return(parse(inJ)); }
private static void closeQuietly(java.io.InputStream inJ) { if (inJ == null) { return; } try { inJ.close(); } catch (java.io.IOException e) { } }
/** * @param encoding the encoding to use for file names, use null * for the platform's default encoding * @param useUnicodeExtraFields whether to use InfoZIP Unicode * Extra Fields (if present) to set the file names. * @param allowStoredEntriesWithDataDescriptor whether the stream * will try to read STORED entries that use a data descriptor * @since Apache Commons Compress 1.1 */ public ZipArchiveInputStream(java.io.InputStream inputStream, String encoding, bool useUnicodeExtraFields, bool allowStoredEntriesWithDataDescriptor) { zipEncoding = ZipEncodingHelper.getZipEncoding(encoding); this.useUnicodeExtraFields = useUnicodeExtraFields; inJ = new java.io.PushbackInputStream(inputStream, buf.Length); this.allowStoredEntriesWithDataDescriptor = allowStoredEntriesWithDataDescriptor; }
/* * Read a two-byte short in little-endian order. */ internal int readShortLE(java.io.InputStream inJ) //throws IOException { if (inJ.read(b, 0, 2) == 2) { return((b[0] & 0XFF) | ((b[1] & 0XFF) << 8)); } else { throw new java.io.EOFException();//Messages.getString("archive.3C")); } }
/** * Construct a change which adds an entry. * * @param pEntry the entry details * @param pInput the InputStream for the entry data */ internal protected Change(ArchiveEntry pEntry, java.io.InputStream pInput, bool replace) { if (pEntry == null || pInput == null) { throw new java.lang.NullPointerException(); } this.entry = pEntry; this.input = pInput; typeJ = TYPE_ADD; targetFileJ = null; this.replaceMode = replace; }
/* * Imports all the preferences from an XML document using the given input * stream. * <p> * This XML document uses the UTF-8 encoding and must be written according * to the DTD in its DOCTYPE declaration, which must be the following: * * <pre> * <!DOCTYPE preferences SYSTEM "http://java.sun.com/dtd/preferences.dtd"> * </pre> * * <i>Please note that (unlike the methods of this class that don't concern * serialization), this call is not thread-safe.</i> * </p> * * @param istream * the input stream to read the data from. * @throws InvalidPreferencesFormatException * if the data read from the given input stream is not from a * valid XML document. * @throws IOException * if an error occurs while importing. * @throws SecurityException * if {@code RuntimePermission("preferences")} is denied by a * SecurityManager. */ public static void importPreferences(java.io.InputStream istream) {//throws InvalidPreferencesFormatException, IOException { checkSecurity(); if (null == istream) { // prefs.0=Input stream cannot be null throw new java.net.MalformedURLException("Input stream cannot be null"); //$NON-NLS-1$ } throw new java.lang.UnsupportedOperationException("XMLParser not implemented"); // TODO: implement XMLParser... //XMLParser.importPrefs(istream); }
/** * Constructor. Takes the filename of the file to be deleted * from the stream as argument. * @param pFilename the filename of the file to delete */ internal protected Change(String pFilename, int type) { if (pFilename == null) { throw new java.lang.NullPointerException(); } this.targetFileJ = pFilename; this.typeJ = type; this.input = null; this.entry = null; this.replaceMode = true; }
/// <summary> /// Creates an InputStream for given resource. Resources are define as path with slash separator /. /// Returns null if no resource found. /// </summary> /// <param name="name"></param> /// <returns>InputSteam or null</returns> public java.io.InputStream getResourceAsStream(String name) { java.io.InputStream result = null; if (null != getParent()) { result = getParent().getResourceAsStream(name); } if (null == result) { java.net.URL url = this.findResource(name); } return(result); }
/** * Read through an InputStream and returns the digest for the data * * @param digest * The MessageDigest to use (e.g. MD5) * @param data * Data to digest * @return MD5 digest * @throws IOException * On error reading from the stream */ private static byte[] digest(java.security.MessageDigest digest, java.io.InputStream data) {//throws IOException { byte[] buffer = new byte[STREAM_BUFFER_LENGTH]; int read = data.read(buffer, 0, STREAM_BUFFER_LENGTH); while (read > -1) { digest.update(buffer, 0, read); read = data.read(buffer, 0, STREAM_BUFFER_LENGTH); } return(digest.digest()); }
/** * Constructs a DeflaterInputStream with a specified Deflater and input * buffer length. * * @param in * the InputStream that the DeflaterInputStream reads data from. * @param defl * a specifed Deflater used to compress data. * @param bufLen * the buffer length of the internal input data buffer. */ public DeflaterInputStream(java.io.InputStream inJ, Deflater defl, int bufLen) : base(inJ) { if (null == inJ || null == defl) { throw new java.lang.NullPointerException(); } if (bufLen <= 0) { throw new java.lang.IllegalArgumentException(); } def = defl; buf = new byte[bufLen]; }
/** * Copies the content of a InputStream into an OutputStream * * @param input * the InputStream to copy * @param output * the target Stream * @param buffersize * the buffer size to use * @throws IOException * if an error occurs */ public static long copy(java.io.InputStream input, java.io.OutputStream output, int buffersize) //throws IOException { byte[] buffer = new byte[buffersize]; int n = 0; long count = 0; while (-1 != (n = input.read(buffer))) { output.write(buffer, 0, n); count += n; } return(count); }
static internal byte [] toByteArray(java.io.InputStream inJ) { java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream(); byte[] buffer = new byte[32 * 1024]; int bytesRead; while ((bytesRead = inJ.read(buffer)) > 0) { baos.write(buffer, 0, bytesRead); } byte[] bytes = baos.toByteArray(); return(bytes); }
/** * Create an archive input stream from an input stream, autodetecting * the archive type from the first few bytes of the stream. The InputStream * must support marks, like BufferedInputStream. * * @param in the input stream * @return the archive input stream * @throws ArchiveException if the archiver name is not known * @throws IllegalArgumentException if the stream is null or does not support mark */ public ArchiveInputStream createArchiveInputStream(java.io.InputStream inJ) //throws ArchiveException { if (inJ == null) { throw new java.lang.IllegalArgumentException("Stream must not be null."); } if (!inJ.markSupported()) { throw new java.lang.IllegalArgumentException("Mark is not supported."); } byte[] signature = new byte[12]; inJ.mark(signature.Length); try { int signatureLength = inJ.read(signature); inJ.reset(); if (ZipArchiveInputStream.matches(signature, signatureLength)) { return(new ZipArchiveInputStream(inJ)); } else if (JarArchiveInputStream.matches(signature, signatureLength)) { return(new JarArchiveInputStream(inJ)); } else if (ArArchiveInputStream.matches(signature, signatureLength)) { return(new ArArchiveInputStream(inJ)); } else if (CpioArchiveInputStream.matches(signature, signatureLength)) { return(new CpioArchiveInputStream(inJ)); } // Tar needs a bigger buffer to check the signature; read the first block byte[] tarheader = new byte[512]; inJ.mark(tarheader.Length); signatureLength = inJ.read(tarheader); inJ.reset(); if (TarArchiveInputStream.matches(tarheader, signatureLength)) { return(new TarArchiveInputStream(inJ)); } } catch (java.io.IOException e) { throw new ArchiveException("Could not use reset and mark operations.", e); } throw new ArchiveException("No Archiver found for the stream signature"); }
/** * Set the byte stream for this input source. * * <p>The SAX parser will ignore this if there is also a character * stream specified, but it will use a byte stream in preference * to opening a URI connection itself.</p> * * <p>If the application knows the character encoding of the * byte stream, it should set it with the setEncoding method.</p> * * @param byteStream A byte stream containing an XML document or * other entity. * @see #setEncoding * @see #getByteStream * @see #getEncoding * @see java.io.InputStream */ public void setByteStream(java.io.InputStream byteStream) { this.byteStream = byteStream; }
static SystemJ() { outJ = new dotnet.lang.ConsoleOutputPrintStream(); inJ = new dotnet.lang.ConsoleInputStream(); err = new dotnet.lang.ConsoleErrorPrintStream(); }
public StreamInputWrapper(java.io.InputStream inputStream) { this.delegateInstance = inputStream; }
public void setOut(java.io.InputStream inputStream) { inJ = inputStream; }
public StreamWrapper(java.io.InputStream input, java.io.OutputStream output) { this.input = input; this.output = output; }