拷贝流，使用NIO，不会关闭流

@param in {@link ReadableByteChannel}
@param out {@link WritableByteChannel}
@return 拷贝的字节数
@throws IORuntimeException IO异常
@since 4.5.0
484194
public static long copy(ReadableByteChannel in, WritableByteChannel out) throws IORuntimeException {
		return copy(in, out, DEFAULT_BUFFER_SIZE);
	}
717504
@Override
  public void writeTo(StreamOutput out) throws IOException {
    super.writeTo(out);

    out.writeOptionalString(routing);
    out.writeOptionalString(preference);

    if (querySource != null) {
      out.writeBoolean(true);
      out.writeBytesReference(querySource);
    } else {
      out.writeBoolean(false);
    }

    if (types == null) {
      out.writeBoolean(false);
    } else {
      out.writeBoolean(true);
      out.writeStringArray(types);
    }

    out.writeString(field);
    out.writeVLong(nowInMillis);

    if (ordering == null) {
      out.writeBoolean(false);
    } else {
      out.writeBoolean(true);
      out.writeVInt(ordering.ordinal());
    }

    if (maxTermsPerShard == null) {
      out.writeBoolean(false);
    } else {
      out.writeBoolean(true);
      out.writeVInt(maxTermsPerShard);
    }

    if (termsEncoding == null) {
      out.writeBoolean(false);
    } else {
      out.writeBoolean(true);
      out.writeVInt(termsEncoding.ordinal());
    }

    if (expectedTerms == null) {
      out.writeBoolean(false);
    }
    else {
      out.writeBoolean(true);
      out.writeVLong(expectedTerms);
    }
  }
528235
public static File writeToStream(File file, OutputStream out) throws IORuntimeException {
		return FileReader.create(file).writeToStream(out);
	}
1128128
@SuppressWarnings("unchecked")
  public static Object readObject(DataInput in, ObjectWritable objectWritable, Configuration conf)
    throws IOException {
    String className = UTF8.readString(in);
    
    // fast processing of ShortVoid
    if (FastWritableRegister.isVoidType(className)) {
      setObjectWritable(objectWritable, ShortVoid.class, ShortVoid.instance);
      return ShortVoid.instance;
    }
    
    // handle fast writable objects first
    FastWritable fwInstance = FastWritableRegister.tryGetInstance(className,
        conf);
    if (fwInstance != null) {
      fwInstance.readFields(in);
      setObjectWritable(objectWritable, fwInstance.getClass(), fwInstance);
      return fwInstance;
    }
    
    Class<?> declaredClass = getClassWithCaching(className, conf);
    
    // read once whether we should support jobconf
    // HDFS does not need to support this, which saves on Writable.newInstance
    if (!initializedSupportJobConf) {
      supportJobConf = conf.getBoolean("rpc.support.jobconf", true);
      // since this is not synchronized, there is a race condition here
      // but we are ok with two instances initializing this
      // if the operations are re-ordered, it is still fine, another thread
      // might use "true" instead of false for one time
      initializedSupportJobConf = true;
    }

    Object instance;
    
    if (declaredClass.isPrimitive()) {            // primitive types

      if (declaredClass == Boolean.TYPE) {             // boolean
        instance = Boolean.valueOf(in.readBoolean());
      } else if (declaredClass == Character.TYPE) {    // char
        instance = Character.valueOf(in.readChar());
      } else if (declaredClass == Byte.TYPE) {         // byte
        instance = Byte.valueOf(in.readByte());
      } else if (declaredClass == Short.TYPE) {        // short
        instance = Short.valueOf(in.readShort());
      } else if (declaredClass == Integer.TYPE) {      // int
        instance = Integer.valueOf(in.readInt());
      } else if (declaredClass == Long.TYPE) {         // long
        instance = Long.valueOf(in.readLong());
      } else if (declaredClass == Float.TYPE) {        // float
        instance = Float.valueOf(in.readFloat());
      } else if (declaredClass == Double.TYPE) {       // double
        instance = Double.valueOf(in.readDouble());
      } else if (declaredClass == Void.TYPE) {         // void
        instance = null;
      } else {
        throw new IllegalArgumentException("Not a primitive: "+declaredClass);
      }

    } else if (declaredClass.isArray()) {              // array
      int length = in.readInt();
      instance = Array.newInstance(declaredClass.getComponentType(), length);
      for (int i = 0; i < length; i++) {
        Array.set(instance, i, readObject(in, conf));
      }
      
    } else if (declaredClass == String.class) {        // String
      instance = UTF8.readString(in);
    } else if (declaredClass.isEnum()) {         // enum
      instance = Enum.valueOf((Class<? extends Enum>) declaredClass, UTF8.readString(in));
    } else {                                      // Writable
      String str = UTF8.readString(in);
      Class instanceClass = getClassWithCaching(str, conf);
      
      Writable writable = WritableFactories.newInstance(instanceClass, conf, supportJobConf);
      writable.readFields(in);
      instance = writable;

      if (instanceClass == NullInstance.class) {  // null
        declaredClass = ((NullInstance)instance).declaredClass;
        instance = null;
      }
    }
    setObjectWritable(objectWritable, declaredClass, instance);
    return instance;
      
  }
690067
public static void writeUtf8(OutputStream out, boolean isCloseOut, Object... contents) throws IORuntimeException {
		write(out, CharsetUtil.CHARSET_UTF_8, isCloseOut, contents);
	}
461086
public static <T> Iterable<T> toIterable(Enumeration<T> in) {
        List<T> out = new LinkedList<T>();
        while(in.hasMoreElements()) {
            out.add(in.nextElement());
        }
        return out;
    }
147851
public static void writeToStream(String fullFilePath, OutputStream out) throws IORuntimeException {
		writeToStream(touch(fullFilePath), out);
	}
839013
@Override
    public void readExternal(ObjectInput in)
        throws IOException, ClassNotFoundException {

        byte header = in.readByte();

        switch ((header & 0xFF) >> 4) {
            case DATE_TYPE:
                this.obj = this.readDate(in, header);
                break;
            case TIME_TYPE:
                this.obj = this.readTime(in);
                break;
            case WEEKMODEL_TYPE:
                this.obj = this.readWeekmodel(in, header);
                break;
            case MOMENT_TYPE:
                this.obj = this.readMoment(in, header);
                break;
            case MACHINE_TIME_TYPE:
                this.obj = this.readMachineTime(in, header);
                break;
            case DURATION_TYPE:
                this.obj = this.readDuration(in, header);
                break;
            case DAY_PERIOD_TYPE:
                this.obj = this.readDayPeriod(in, header);
                break;
            case TIMESTAMP_TYPE:
                this.obj = this.readTimestamp(in, header);
                break;
            default:
                throw new StreamCorruptedException("Unknown serialized type.");
        }

    }
940572
private void writeObject(java.io.ObjectOutputStream out) throws IOException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "writeObject : " + this); // d468174

        out.writeObject(ivPuRefId);
        out.writeObject(ivJ2eeName); // d510184
        out.writeObject(ivRefName); // d510184
        out.writeObject(ivProperties);
        out.writeBoolean(ivUnsynchronized);

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "writeObject : " + this);
    }
336025
public static void run(final RunType runInto, final JRebirthRunnable runnable, final long... timeout) {
        switch (runInto) {
            case JAT:
                runIntoJAT(runnable);
                break;
            case JAT_SYNC:
                runIntoJATSync(runnable, timeout);
                break;
            case JIT:
                runIntoJIT(runnable);
                break;
            case JIT_SYNC:
                runIntoJITSync(runnable, timeout);
                break;
            case JTP:
                runIntoJTP(runnable);
                break;
            case JTP_SYNC:
                runIntoJTPSync(runnable, timeout);
                break;
            case SAME:
            default:
                runnable.run();
        }
    }
1070384
public Word07Writer flush(OutputStream out, boolean isCloseOut) throws IORuntimeException {
		Assert.isFalse(this.isClosed, "WordWriter has been closed!");
		try {
			this.doc.write(out);
			out.flush();
		} catch (IOException e) {
			throw new IORuntimeException(e);
		} finally {
			if (isCloseOut) {
				IoUtil.close(out);
			}
		}
		return this;
	}
14161
public <T> File writeLines(Collection<T> list) throws IORuntimeException {
		return writeLines(list, false);
	}
41393
public static void write(OutputStream out, boolean isCloseOut, byte[] content) throws IORuntimeException {
		try {
			out.write(content);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		} finally {
			if (isCloseOut) {
				close(out);
			}
		}
	}
938995
public WritableByteChannel reset(WritableByteChannel channel)
            throws IOException
    {
        WritableByteChannel old = this.channel;
        this.channel = channel;
        return old;
    }
904843
public Format run( ReadableChannelWrapper in) throws IOException {
		Format format = new Format();
        	Key< Integer> headerStartKey = in.start();
		
		Key< Integer> lead = in.start();
		format.getLead().read( in);
		log( "Lead ended at '" + in.finish( lead) + "'.");

		Key< Integer> signature = in.start();
		int count = format.getSignature().read( in);
		Entry<?> sigEntry = format.getSignature().getEntry(SIGNATURES);
		int expected = sigEntry == null ? 0:  ByteBuffer.wrap(( byte[]) sigEntry.getValues(), 8, 4).getInt() / -16;
		log( "Signature ended at '" + in.finish( signature) + "' and contained '" + count + "' headers (expected '" + expected + "').");

        	Integer headerStartPos = in.finish(headerStartKey);
        	format.getHeader().setStartPos(headerStartPos);
		Key< Integer> headerKey = in.start();
		count = format.getHeader().read( in);
		Entry<?> immutableEntry = format.getHeader().getEntry( HEADERIMMUTABLE);
		expected = immutableEntry == null ? 0 : ByteBuffer.wrap(( byte[]) immutableEntry.getValues(), 8, 4).getInt() / -16;
        	Integer headerLength = in.finish(headerKey);
        	format.getHeader().setEndPos(headerStartPos + headerLength);
        	log( "Header ended at '" + headerLength + " and contained '" + count + "' headers (expected '" + expected + "').");

		return format;
	}
994377
private void writeObject(java.io.ObjectOutputStream out) throws IOException
    {
        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.entry(tc, "writeObject : " + ivPuId + ", " + ivJ2eeName);

        out.writeObject(ivPuId);
        out.writeObject(ivJ2eeName); // d510184

        if (TraceComponent.isAnyTracingEnabled() && tc.isEntryEnabled())
            Tr.exit(tc, "writeObject");
    }
104396
private void writeInbound(Definition def, Writer out, int indent) throws IOException
   {
      writeIndent(out, indent);
      out.write("<inbound-resourceadapter>");
      writeEol(out);
      writeIndent(out, indent + 1);
      out.write("<messageadapter>");
      writeEol(out);
      writeIndent(out, indent + 2);
      out.write("<messagelistener>");
      writeEol(out);
      writeIndent(out, indent + 3);
      if (!def.isDefaultPackageInbound())
      {
         out.write("<messagelistener-type>" + def.getMlClass() + "</messagelistener-type>");
      }
      else
      {
         out.write("<messagelistener-type>" + def.getRaPackage() +
               ".inflow." + def.getMlClass() + "</messagelistener-type>");
      }
      writeEol(out);
      writeIndent(out, indent + 3);
      out.write("<activationspec>");
      writeEol(out);
      writeIndent(out, indent + 4);
      out.write("<activationspec-class>" + def.getRaPackage() +
            ".inflow." + def.getAsClass() + "</activationspec-class>");
      writeEol(out);

      writeAsConfigPropsXml(def.getAsConfigProps(), out, indent + 4);
      writeIndent(out, indent + 3);
      out.write("</activationspec>");
      writeEol(out);
      writeIndent(out, indent + 2);
      out.write("</messagelistener>");
      writeEol(out);
      writeIndent(out, indent + 1);
      out.write("</messageadapter>");
      writeEol(out);
      writeIndent(out, indent);
      out.write("</inbound-resourceadapter>");
      writeEol(out);
   }