Module java.desktop

Class ImageOutputStreamImpl

java.lang.Object
javax.imageio.stream.ImageInputStreamImpl
javax.imageio.stream.ImageOutputStreamImpl
所有已实现的接口:
Closeable, DataInput, DataOutput, AutoCloseable, ImageInputStream, ImageOutputStream
直接已知的子类:
FileCacheImageOutputStream, FileImageOutputStream, MemoryCacheImageOutputStream

public abstract class ImageOutputStreamImpl extends ImageInputStreamImpl implements ImageOutputStream
实现ImageOutputStream接口的抽象类。该类旨在减少子类必须实现的方法数量。
  • Constructor Details

    • ImageOutputStreamImpl

      public ImageOutputStreamImpl()
      构造一个ImageOutputStreamImpl
  • Method Details

    • write

      public void write(byte[] b) throws IOException
      从接口复制的描述: ImageOutputStream
      将一系列字节写入当前位置的流。如果b.length为0,则不写入任何内容。首先写入字节b[0],然后是字节b[1],依此类推。

      如果流中的位偏移量非零,则当前字节的其余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      write 在接口 DataOutput
      指定者:
      write 在接口 ImageOutputStream
      参数:
      b - 要写入的byte数组。
      抛出:
      IOException - 如果发生I/O错误。
    • writeBoolean

      public void writeBoolean(boolean v) throws IOException
      从接口复制的描述: ImageOutputStream
      boolean值写入流。如果v为true,则写入值(byte)1;如果v为false,则写入值(byte)0

      如果流中的位偏移量非零,则当前字节的其余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeBoolean 在接口 DataOutput
      指定者:
      writeBoolean 在接口 ImageOutputStream
      参数:
      v - 要写入的boolean值。
      抛出:
      IOException - 如果发生I/O错误。
    • writeByte

      public void writeByte(int v) throws IOException
      从接口复制的描述: ImageOutputStream
      v的8个低位写入流。忽略v的24个高位。(这意味着对于整数参数,writeBytewrite完全相同。)

      如果流中的位偏移量非零,则当前字节的其余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeByte 在接口 DataOutput
      指定者:
      writeByte 在接口 ImageOutputStream
      参数:
      v - 包含要写入的字节值的int
      抛出:
      IOException - 如果发生I/O错误。
    • writeShort

      public void writeShort(int v) throws IOException
      从接口复制的描述: ImageOutputStream
      Writes the 16 low-order bits of v to the stream. The 16 high-order bits of v are ignored. If the stream uses network byte order, the bytes written, in order, will be:
       (byte)((v >> 8) & 0xff)
       (byte)(v & 0xff)
       
      Otherwise, the bytes written will be:
       (byte)(v & 0xff)
       (byte)((v >> 8) & 0xff)
       

      If the bit offset within the stream is non-zero, the remainder of the current byte is padded with 0s and written out first. The bit offset will be 0 after the write.

      Specified by:
      writeShort in interface DataOutput
      Specified by:
      writeShort in interface ImageOutputStream
      Parameters:
      v - an int containing the short value to be written.
      Throws:
      IOException - if an I/O error occurs.
    • writeChar

      public void writeChar(int v) throws IOException
      Description copied from interface: ImageOutputStream
      This method is a synonym for writeShort.
      Specified by:
      writeChar in interface DataOutput
      Specified by:
      writeChar in interface ImageOutputStream
      Parameters:
      v - an int containing the char (unsigned short) value to be written.
      Throws:
      IOException - if an I/O error occurs.
      See Also:
    • writeInt

      public void writeInt(int v) throws IOException
      Description copied from interface: ImageOutputStream
      v的32位写入流。如果流使用网络字节顺序,则按顺序写入的字节将是:
       (byte)((v >> 24) & 0xff)
       (byte)((v >> 16) & 0xff)
       (byte)((v >> 8) & 0xff)
       (byte)(v & 0xff)
       
      否则,将写入的字节为:
       (byte)(v & 0xff)
       (byte)((v >> 8) & 0xff)
       (byte)((v >> 16) & 0xff)
       (byte)((v >> 24) & 0xff)
       

      如果流中的位偏移量不为零,则当前字节的剩余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeInt 在接口 DataOutput
      指定者:
      writeInt 在接口 ImageOutputStream
      参数:
      v - 包含要写入的值的int
      抛出:
      IOException - 如果发生I/O错误。
    • writeLong

      public void writeLong(long v) throws IOException
      从接口中复制的描述: ImageOutputStream
      v的64位写入流。如果流使用网络字节顺序,则按顺序写入的字节将是:
       (byte)((v >> 56) & 0xff)
       (byte)((v >> 48) & 0xff)
       (byte)((v >> 40) & 0xff)
       (byte)((v >> 32) & 0xff)
       (byte)((v >> 24) & 0xff)
       (byte)((v >> 16) & 0xff)
       (byte)((v >> 8) & 0xff)
       (byte)(v & 0xff)
       
      否则,将写入的字节为:
       (byte)(v & 0xff)
       (byte)((v >> 8) & 0xff)
       (byte)((v >> 16) & 0xff)
       (byte)((v >> 24) & 0xff)
       (byte)((v >> 32) & 0xff)
       (byte)((v >> 40) & 0xff)
       (byte)((v >> 48) & 0xff)
       (byte)((v >> 56) & 0xff)
       

      如果流中的位偏移量不为零,则当前字节的剩余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeLong 在接口 DataOutput
      指定者:
      writeLong 在接口 ImageOutputStream
      参数:
      v - 包含要写入的值的long
      抛出:
      IOException - 如果发生I/O错误。
    • writeFloat

      public void writeFloat(float v) throws IOException
      从接口中复制的描述: ImageOutputStream
      将由四个字节组成的float值写入输出流。它会将此float值转换为int,方法与Float.floatToIntBits方法完全相同,然后按照writeInt方法的方式写入int值。

      如果流中的位偏移量不为零,则当前字节的剩余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeFloat 在接口 DataOutput
      指定者:
      writeFloat 在接口 ImageOutputStream
      参数:
      v - 包含要写入的值的float
      抛出:
      IOException - 如果发生I/O错误。
    • writeDouble

      public void writeDouble(double v) throws IOException
      从接口中复制的描述: ImageOutputStream
      将由八个字节组成的double值写入输出流。它会将此double值转换为long,方法与Double.doubleToLongBits方法完全相同,然后按照writeLong方法的方式写入long值。

      如果流中的位偏移量不为零,则当前字节的剩余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeDouble 在接口 DataOutput
      指定者:
      writeDouble 在接口 ImageOutputStream
      参数:
      v - 包含要写入的值的double
      抛出:
      IOException - 如果发生I/O错误。
    • writeBytes

      public void writeBytes(String s) throws IOException
      从接口中复制的描述: ImageOutputStream
      将字符串写入输出流。对于字符串s中的每个字符,按顺序写入一个字节到输出流。如果snull,则会抛出NullPointerException

      如果s.length为零,则不会写入任何字节。否则,首先写入字符s[0],然后是s[1],依此类推;最后一个写入的字符是s[s.length-1]。对于每个字符,将写入一个字节,即低位字节,方式与writeByte方法完全相同。字符串中每个字符的高位八位将被忽略。

      如果流中的位偏移量不为零,则当前字节的剩余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeBytes 在接口 DataOutput
      指定者:
      writeBytes 在接口 ImageOutputStream
      参数:
      s - 包含要写入的值的String
      抛出:
      IOException - 如果发生I/O错误。
    • writeChars

      public void writeChars(String s) throws IOException
      从接口中复制的描述: ImageOutputStream
      将字符串写入输出流。对于字符串s中的每个字符,按顺序写入两个字节到输出流,根据当前的字节顺序设置排序。如果使用网络字节顺序,则首先写入高位字节;否则顺序相反。如果snull,则会抛出NullPointerException

      如果s.length为零,则不会写入任何字节。否则,首先写入字符s[0],然后是s[1],依此类推;最后一个写入的字符是s[s.length-1]

      如果流中的位偏移量不为零,则当前字节的剩余部分将填充为0并首先写出。写入后,位偏移量将为0。

      指定者:
      writeChars 在接口 DataOutput
      指定者:
      writeChars 在接口 ImageOutputStream
      参数:
      s - 包含要写入的值的String
      抛出:
      IOException - 如果发生I/O错误。
    • writeUTF

      public void writeUTF(String s) throws IOException
      从接口中复制的描述: ImageOutputStream
      在网络字节顺序中向输出流写入两个字节的长度信息,然后跟随字符串 s 中每个字符的修改后的UTF-8表示。如果 snull,则会抛出 NullPointerException。字符串 s 中的每个字符根据字符的值转换为一个、两个或三个字节的组。

      如果字符 c 在范围 \u0001\u007f 内,则用一个字节表示:

       (byte)c
       

      如果字符 c\u0000 或在范围 \u0080\u07ff 内,则用两个字节表示,按照以下顺序写入:

      
       (byte)(0xc0 | (0x1f & (c >> 6)))
       (byte)(0x80 | (0x3f & c))
       

      如果字符 c 在范围 \u0800uffff 内,则用三个字节表示,按照以下顺序写入:

      
       (byte)(0xe0 | (0x0f & (c >> 12)))
       (byte)(0x80 | (0x3f & (c >> 6)))
       (byte)(0x80 | (0x3f & c))
       

      首先计算表示字符串 s 中所有字符所需的总字节数。如果此数字大于 65535,则会抛出 UTFDataFormatException。否则,将以与 writeShort 方法完全相同的方式将此长度写入输出流;之后,将字符串 s 中每个字符的一个、两个或三个字节表示写入。

      当前的字节顺序设置将被忽略。

      如果流中的位偏移量不为零,则当前字节的剩余部分将首先填充为 0 并写出。写入后,位偏移量将为 0。

      注意:不应在使用标准UTF-8的图像格式的实现中使用此方法,因为此处使用的修改后的UTF-8与标准UTF-8不兼容。

      指定者:
      writeUTF 在接口 DataOutput
      指定者:
      writeUTF 在接口 ImageOutputStream
      参数:
      s - 包含要写入的值的 String
      抛出:
      UTFDataFormatException - 如果 s 的修改后的UTF-8表示需要超过65536字节。
      IOException - 如果发生I/O错误。
    • writeShorts

      public void writeShorts(short[] s, int off, int len) throws IOException
      从接口中复制的描述: ImageOutputStream
      在当前位置向流写入一系列short。如果 len 为0,则不会写入任何内容。首先写入short s[off],然后是short s[off + 1],依此类推。流的字节顺序用于确定写入单个字节的顺序。

      如果流中的位偏移量不为零,则当前字节的剩余部分将首先填充为 0 并写出。写入后,位偏移量将为 0。

      指定者:
      writeShorts 在接口 ImageOutputStream
      参数:
      s - 要写入的 short 数组。
      off - 数据中的起始偏移量。
      len - 要写入的 short 数量。
      抛出:
      IOException - 如果发生I/O错误。
    • writeChars

      public void writeChars(char[] c, int off, int len) throws IOException
      从接口中复制的描述: ImageOutputStream
      在当前位置向流写入一系列char。如果 len 为0,则不会写入任何内容。首先写入char c[off],然后是char c[off + 1],依此类推。流的字节顺序用于确定写入单个字节的顺序。

      如果流中的位偏移量不为零,则当前字节的剩余部分将首先填充为 0 并写出。写入后,位偏移量将为 0。

      指定者:
      writeChars 在接口 ImageOutputStream
      参数:
      c - 要写入的 char 数组。
      off - 数据中的起始偏移量。
      len - 要写入的 char 数量。
      抛出:
      IOException - 如果发生I/O错误。
    • writeInts

      public void writeInts(int[] i, int off, int len) throws IOException
      从接口中复制的描述: ImageOutputStream
      在当前位置向流写入一系列int。如果 len 为0,则不会写入任何内容。首先写入int i[off],然后是int i[off + 1],依此类推。流的字节顺序用于确定写入单个字节的顺序。

      如果流中的位偏移量不为零,则当前字节的剩余部分将首先填充为 0 并写出。写入后,位偏移量将为 0。

      指定者:
      writeInts 在接口 ImageOutputStream
      参数:
      i - 要写入的 int 数组。
      off - 数据中的起始偏移量。
      len - 要写入的 int 数量。
      抛出:
      IOException - 如果发生I/O错误。
    • writeLongs

      public void writeLongs(long[] l, int off, int len) throws IOException
      从接口中复制的描述: ImageOutputStream
      在当前位置向流写入一系列long。如果 len 为0,则不会写入任何内容。首先写入long l[off],然后是long l[off + 1],依此类推。流的字节顺序用于确定写入单个字节的顺序。

      如果流中的位偏移量不为零,则当前字节的剩余部分将首先填充为 0 并写出。写入后,位偏移量将为 0。

      指定者:
      writeLongs 在接口 ImageOutputStream
      参数:
      l - 要写入的 long 数组。
      off - 数据中的起始偏移量。
      len - 要写入的 long 数量。
      抛出:
      IOException - 如果发生I/O错误。
    • writeFloats

      public void writeFloats(float[] f, int off, int len) throws IOException
      从接口中复制的描述: ImageOutputStream
      在当前位置向流写入一系列float。如果 len 为0,则不会写入任何内容。首先写入float f[off],然后是float f[off + 1],依此类推。流的字节顺序用于确定写入单个字节的顺序。

      如果流中的位偏移量不为零,则当前字节的剩余部分将首先填充为 0 并写出。写入后,位偏移量将为 0。

      指定者:
      writeFloats 在接口 ImageOutputStream
      参数:
      f - 要写入的 float 数组。
      off - 数据中的起始偏移量。
      len - 要写入的 float 数量。
      抛出:
      IOException - 如果发生I/O错误。
    • writeDoubles

      public void writeDoubles(double[] d, int off, int len) throws IOException
      从接口中复制的描述: ImageOutputStream
      在当前位置向流写入一系列double。如果 len 为0,则不会写入任何内容。首先写入double d[off],然后是double d[off + 1],依此类推。流的字节顺序用于确定写入单个字节的顺序。

      如果流中的位偏移量不为零,则当前字节的剩余部分将首先填充为 0 并写出。写入后,位偏移量将为 0。

      指定者:
      writeDoubles 在接口 ImageOutputStream
      参数:
      d - 要写入的double数组。
      off - 数据中的起始偏移量。
      len - 要写入的double数量。
      抛出:
      IOException - 如果发生I/O错误。
    • writeBit

      public void writeBit(int bit) throws IOException
      从接口复制的描述: ImageOutputStream
      将给定参数的最低有效位写入流中的当前位偏移位置的当前字节位置。参数的高31位将被忽略。给定位替换该位置的先前位。位偏移量增加1,并对8取模。

      如果在将字节刷新到目标时,特定字节的任何位从未被设置过,则这些位将自动设置为0。

      指定者:
      writeBit 在接口 ImageOutputStream
      参数:
      bit - 要写入流中的最低有效位的int
      抛出:
      IOException - 如果发生I/O错误。
    • writeBits

      public void writeBits(long bits, int numBits) throws IOException
      从接口复制的描述: ImageOutputStream
      将给定参数bits中的numBits最低有效位按从左到右的顺序写入流中的当前位偏移位置的当前字节位置。参数的高64 - numBits位将被忽略。位偏移量增加numBits,并对8取模。请注意,位偏移量为0始终表示字节的最高有效位,并且按照遇到的顺序写出位的字节。因此,位写入实际上总是按照网络字节顺序进行。实际的流字节顺序设置将被忽略。

      位数据可能会在内存中无限累积,直到调用flushBefore。在那时,将写入到刷新位置之前的所有位数据。

      如果在将字节刷新到目标时,特定字节的任何位从未被设置过,则这些位将自动设置为0。

      指定者:
      writeBits 在接口 ImageOutputStream
      参数:
      bits - 包含要写入的位的long,从位于位置numBits - 1的位到最低有效位。
      numBits - 介于0和64之间的int,包括0和64。
      抛出:
      IOException - 如果发生I/O错误。
    • flushBits

      protected final void flushBits() throws IOException
      如果位偏移量不为零,则将当前字节中剩余的位强制设置为0,并将流位置向前移动一个位置。子类应在write(int)write(byte[], int, int)方法的开头调用此方法。
      抛出:
      IOException - 如果发生I/O错误。