상속: java.io.FilterOutputStream
예제 #1
0
		internal DeflateStream (Stream compressedStream, CompressionMode mode, bool leaveOpen, bool gzip) {
			if (compressedStream == null)
				throw new ArgumentNullException ("compressedStream");

			switch (mode) {
			case CompressionMode.Compress:
				if (!compressedStream.CanWrite)
					throw new ArgumentException ("The base stream is not writeable.");
				OutputStream outStream = new OutputStreamImpl(compressedStream);
				_writer = gzip ? new GZIPOutputStream (outStream) : new DeflaterOutputStream (outStream, new Deflater (Deflater.DEFAULT_COMPRESSION, true));
				break;
			case CompressionMode.Decompress:
				if (!compressedStream.CanRead)
					throw new ArgumentException ("The base stream is not readable.");
				InputStream inStream = new InputStreamImpl (compressedStream);
				_reader = gzip ? new GZIPInputStream (inStream) : new InflaterInputStream (inStream, new Inflater (true));
				break;
			default:
				throw new ArgumentException ("mode");
			}

			_baseStream = compressedStream;
			_leaveOpen = leaveOpen;
			_open = true;
		}
예제 #2
0
    protected internal virtual bool writeImageData()
    {
      int num1 = this.height;
      int num2 = 0;
      this.bytesPerPixel = !this.encodeAlpha ? 3 : 4;
      Deflater deflater = new Deflater(this.compressionLevel);
      ByteArrayOutputStream arrayOutputStream = new ByteArrayOutputStream(1024);
      DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream((OutputStream) arrayOutputStream, deflater);
      IOException ioException1;
      IOException ioException2;
      while (true)
      {
        int num3;
        int[] numArray1;
        PixelGrabber pixelGrabber;
        try
        {
          if (num1 > 0)
          {
            int num4 = (int) short.MaxValue;
            int num5 = this.width * (this.bytesPerPixel + 1);
            int num6 = -1;
            num3 = Math.max(Math.min(num5 != num6 ? num4 / num5 : -num4, num1), 1);
            numArray1 = new int[this.width * num3];
            pixelGrabber = new PixelGrabber(this.image, 0, num2, this.width, num3, numArray1, 0, this.width);
            try
            {
              pixelGrabber.grabPixels();
            }
            catch (Exception ex)
            {
              int num7 = 2;
              if (ByteCodeHelper.MapException<Exception>(ex, (ByteCodeHelper.MapFlags) num7) == null)
                throw;
              else
                break;
            }
          }
          else
            goto label_33;
        }
        catch (IOException ex)
        {
          int num4 = 1;
          ioException1 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num4);
          goto label_8;
        }
        try
        {
          if ((pixelGrabber.getStatus() & 128) != 0)
          {
            System.get_err().println("image fetch aborted or errored");
            return false;
          }
          else
          {
            byte[] pixels = new byte[this.width * num3 * this.bytesPerPixel + num3];
            if (this.filter == 1)
              this.leftBytes = new byte[16];
            if (this.filter == 2)
              this.priorRow = new byte[this.width * this.bytesPerPixel];
            int num4 = 0;
            int startPos = 1;
            for (int index1 = 0; index1 < this.width * num3; ++index1)
            {
              int num5 = index1;
              int num6 = this.width;
              int num7 = -1;
              if ((num6 != num7 ? num5 % num6 : 0) == 0)
              {
                byte[] numArray2 = pixels;
                int index2 = num4;
                ++num4;
                int num8 = (int) (sbyte) this.filter;
                numArray2[index2] = (byte) num8;
                startPos = num4;
              }
              byte[] numArray3 = pixels;
              int index3 = num4;
              int num9 = num4 + 1;
              int num10 = (int) (sbyte) (numArray1[index1] >> 16 & (int) byte.MaxValue);
              numArray3[index3] = (byte) num10;
              byte[] numArray4 = pixels;
              int index4 = num9;
              int num11 = num9 + 1;
              int num12 = (int) (sbyte) (numArray1[index1] >> 8 & (int) byte.MaxValue);
              numArray4[index4] = (byte) num12;
              byte[] numArray5 = pixels;
              int index5 = num11;
              num4 = num11 + 1;
              int num13 = (int) (sbyte) (numArray1[index1] & (int) byte.MaxValue);
              numArray5[index5] = (byte) num13;
              if (this.encodeAlpha)
              {
                byte[] numArray2 = pixels;
                int index2 = num4;
                ++num4;
                int num8 = (int) (sbyte) (numArray1[index1] >> 24 & (int) byte.MaxValue);
                numArray2[index2] = (byte) num8;
              }
              int num14 = index1;
              int num15 = this.width;
              int num16 = -1;
              if ((num15 != num16 ? num14 % num15 : 0) == this.width - 1 && this.filter != 0)
              {
                if (this.filter == 1)
                  this.filterSub(pixels, startPos, this.width);
                if (this.filter == 2)
                  this.filterUp(pixels, startPos, this.width);
              }
            }
            deflaterOutputStream.write(pixels, 0, num4);
            num2 += num3;
            num1 -= num3;
          }
        }
        catch (IOException ex)
        {
          int num4 = 1;
          ioException2 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num4);
          goto label_32;
        }
      }
      IOException ioException3;
      try
      {
        System.get_err().println("interrupted waiting for pixels!");
        return false;
      }
      catch (IOException ex)
      {
        int num3 = 1;
        ioException3 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num3);
      }
      IOException ioException4 = ioException3;
      goto label_37;
label_8:
      ioException4 = ioException1;
      goto label_37;
label_32:
      ioException4 = ioException2;
      goto label_37;
label_33:
      int num17;
      IOException ioException5;
      try
      {
        deflaterOutputStream.close();
        byte[] data = arrayOutputStream.toByteArray();
        int length = data.Length;
        this.crc.reset();
        this.bytePos = this.writeInt4(length, this.bytePos);
        this.bytePos = this.writeBytes(PngEncoder.__\u003C\u003EIDAT, this.bytePos);
        this.crc.update(PngEncoder.__\u003C\u003EIDAT);
        this.bytePos = this.writeBytes(data, length, this.bytePos);
        this.crc.update(data, 0, length);
        this.crcValue = this.crc.getValue();
        this.bytePos = this.writeInt4((int) this.crcValue, this.bytePos);
        deflater.finish();
        deflater.end();
        num17 = 1;
      }
      catch (IOException ex)
      {
        int num3 = 1;
        ioException5 = (IOException) ByteCodeHelper.MapException<IOException>((Exception) ex, (ByteCodeHelper.MapFlags) num3);
        goto label_36;
      }
      return num17 != 0;
label_36:
      ioException4 = ioException5;
label_37:
      System.get_err().println(Throwable.instancehelper_toString((Exception) ioException4));
      return false;
    }