//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public CharReadable apply(final java.io.File file) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: public override CharReadable Apply(File file) { Magic magic = Magic.Of(file); if (magic == Magic.Zip) { // ZIP file ZipFile zipFile = new ZipFile(file); ZipEntry entry = GetSingleSuitableEntry(zipFile); return(wrap(new InputStreamReaderAnonymousInnerClass2(this, zipFile.getInputStream(entry), Charset, file) , file.length())); } else if (magic == Magic.Gzip) { // GZIP file. GZIP isn't an archive like ZIP, so this is purely data that is compressed. // Although a very common way of compressing with GZIP is to use TAR which can combine many // files into one blob, which is then compressed. If that's the case then // the data will look like garbage and the reader will fail for whatever it will be used for. // TODO add tar support GZIPInputStream zipStream = new GZIPInputStream(new FileStream(file, FileMode.Open, FileAccess.Read)); return(wrap(new InputStreamReaderAnonymousInnerClass3(this, zipStream, Charset, file) , file.length())); } else { Stream @in = new FileStream(file, FileMode.Open, FileAccess.Read); Charset usedCharset = this.Charset; if (magic.ImpliesEncoding()) { // Read (and skip) the magic (BOM in this case) from the file we're returning out @in.skip(magic.Length()); usedCharset = magic.Encoding(); } return(wrap(new InputStreamReaderAnonymousInnerClass4(this, @in, usedCharset, file) , file.length())); } }
/// <summary> /// Wraps a <seealso cref="System.IO.Stream_Input"/> in a <seealso cref="CharReadable"/>. /// </summary> /// <param name="stream"> <seealso cref="Reader"/> to wrap. </param> /// <param name="sourceName"> name or description of the source of the stream. </param> /// <param name="charset"> <seealso cref="Charset"/> to use for reading. </param> /// <param name="length"> total number of bytes provided by the reader. </param> /// <returns> a <seealso cref="CharReadable"/> for the <seealso cref="Reader"/>. </returns> /// <exception cref="IOException"> on I/O error. </exception> //JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public static CharReadable wrap(final java.io.InputStream stream, final String sourceName, java.nio.charset.Charset charset, long length) throws java.io.IOException //JAVA TO C# CONVERTER WARNING: 'final' parameters are ignored unless the option to convert to C# 7.2 'in' parameters is selected: public static CharReadable Wrap(Stream stream, string sourceName, Charset charset, long length) { sbyte[] bytes = new sbyte[Magic.Longest()]; PushbackInputStream pushbackStream = new PushbackInputStream(stream, bytes.Length); Charset usedCharset = charset; int read = stream.Read(bytes, 0, bytes.Length); if (read >= 0) { bytes = read < bytes.Length ? Arrays.copyOf(bytes, read) : bytes; Magic magic = Magic.Of(bytes); int excessiveBytes = read; if (magic.ImpliesEncoding()) { // Unread the diff between the BOM and the longest magic we gathered bytes for excessiveBytes -= magic.Length(); usedCharset = magic.Encoding(); } pushbackStream.unread(bytes, read - excessiveBytes, excessiveBytes); } return(wrap(new InputStreamReaderAnonymousInnerClass(pushbackStream, usedCharset, sourceName) , length)); }