各种buffer间拷贝

提供了一系列用于缓冲复制的方法,包括不同类型的源(如InputStream, Reader, String 和 byte[])到目的地(如OutputStream, Writer, String 和 byte[])。这些方法在现代虚拟机中性能优秀,并且鼓励用户指定字符编码。
/*
  * Copyright 2001-2004 The Apache Software Foundation.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
import  java.io.ByteArrayInputStream;
import  java.io.IOException;
import  java.io.InputStream;
import  java.io.InputStreamReader;
import  java.io.OutputStream;
import  java.io.OutputStreamWriter;
import  java.io.Reader;
import  java.io.StringReader;
import  java.io.Writer;

/**
 
  * This class provides static utility methods for buffered
  * copying between sources (<code>InputStream</code>, <code>Reader</code>, <code>String</code> and
  * <code>byte[]</code>) and destinations (<code>OutputStream</code>, <code>Writer</code>,
  * <code>String</code> and <code>byte[]</code>).
 
  *
  * Unless otherwise noted, these <code>copy</code> methods do <em>not</em> flush or close the
  * streams. Often doing so would require making non-portable assumptions about the streams' origin
  * and further use. This means that both streams' <code>close()</code> methods must be called after
  * copying. if one omits this step, then the stream resources (sockets, file descriptors) are
  * released when the associated Stream is garbage-collected. It is not a good idea to rely on this
  * mechanism. For a good overview of the distinction between "memory management" and "resource
  * management", see <a href="http://www.unixreview.com/articles/1998/9804/9804ja/ja.htm">this
  * UnixReview article</a>.
  *
  * For byte-to-char methods, a <code>copy</code> variant allows the encoding
  * to be selected (otherwise the platform default is used). We would like to
  * encourage you to always specify the encoding because relying on the platform
  * default can lead to unexpected results.
  *
  * We don't provide special variants for the <code>copy</code> methods that
  * let you specify the buffer size because in modern VMs the impact on speed
  * seems to be minimal. We're using a default buffer size of 4 KB.
  *
  * The <code>copy</code> methods use an internal buffer when copying. It is therefore advisable
  * <em>not</em> to deliberately wrap the stream arguments to the <code>copy</code> methods in
  * <code>Buffered*</code> streams. For example, don't do the
  * following:
  *
  * <code>copy( new BufferedInputStream( in ), new BufferedOutputStream( out ) );</code>
  *
  * The rationale is as follows:
  *
  * Imagine that an InputStream's read() is a very expensive operation, which would usually suggest
  * wrapping in a BufferedInputStream. The BufferedInputStream works by issuing infrequent
  {@link java.io.InputStream#read(byte[] b, int off, int len)}  requests on the underlying InputStream, to
  * fill an internal buffer, from which further <code>read</code> requests can inexpensively get
  * their data (until the buffer runs out).
  * However, the <code>copy</code> methods do the same thing, keeping an internal buffer,
  * populated by  {@link InputStream#read(byte[] b, int off, int len)}  requests. Having two buffers
  * (or three if the destination stream is also buffered) is pointless, and the unnecessary buffer
  * management hurts performance slightly (about 3%, according to some simple experiments).
  *
  * Behold, intrepid explorers; a map of this class:
  * <pre>
  *       Method      Input               Output          Dependency
  *       ------      -----               ------          -------
  * 1     copy        InputStream         OutputStream    (primitive)
  * 2     copy        Reader              Writer          (primitive)
  *
  * 3     copy        InputStream         Writer          2
  *
  * 4     copy        Reader              OutputStream    2
  *
  * 5     copy        String              OutputStream    2
  * 6     copy        String              Writer          (trivial)
  *
  * 7     copy        byte[]              Writer          3
  * 8     copy        byte[]              OutputStream    (trivial)
  * </pre>
  *
  * Note that only the first two methods shuffle bytes; the rest use these
  * two, or (if possible) copy using native Java copy methods. As there are
  * method variants to specify the encoding, each row may
  * correspond to up to 2 methods.
  *
  * Origin of code: Apache Avalon (Excalibur)
  *
  @author  Peter Donald
  @author  Jeff Turner
  @author  Matthew Hawthorne
  */
public class  CopyUtils
{
     /**
      * Instances should NOT be constructed in standard programming.
      */
     private  CopyUtils ()
     {
     }

     /**
      * Copy bytes from a <code>byte[]</code> to an <code>OutputStream</code>.
      @param  input the byte array to read from
      @param  output the <code>OutputStream</code> to write to
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( byte []  input, OutputStream output throws  IOException
     {
         output.write ( input ) ;
     }

     /**
      * Copy and convert bytes from a <code>byte[]</code> to chars on a
      * <code>Writer</code>.
      * The platform's default encoding is used for the byte-to-char conversion.
      @param  input the byte array to read from
      @param  output the <code>Writer</code> to write to
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( byte []  input, Writer output throws  IOException
     {
         ByteArrayInputStream in =  new  ByteArrayInputStream ( input ) ;
         copy ( in, output ) ;
     }

     /**
      * Copy and convert bytes from a <code>byte[]</code> to chars on a
      * <code>Writer</code>, using the specified encoding.
      @param  input the byte array to read from
      @param  output the <code>Writer</code> to write to
      @param  encoding The name of a supported character encoding. See the
      * <a href="http://www.iana.org/assignments/character-sets">IANA
      * Charset Registry</a> for a list of valid encoding types.
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( byte []  input, Writer output, String encoding throws  IOException
     {
         ByteArrayInputStream in =  new  ByteArrayInputStream ( input ) ;
         copy ( in, output, encoding ) ;
     }

     /**
      * Copy bytes from an <code>InputStream</code> to an <code>OutputStream</code>.
      @param  input the <code>InputStream</code> to read from
      @param  output the <code>OutputStream</code> to write to
      @return  the number of bytes copied
      @throws  IOException In case of an I/O problem
      */
     public static  int  copy ( InputStream input, OutputStream output throws  IOException
     {
         byte []  buffer =  new  byte [ DEFAULT_BUFFER_SIZE ] ;
         int  count =  0 ;
         int  n =  0 ;
         while  ( - !=  ( n = input.read ( buffer )))
         {
             output.write ( buffer,  0 , n ) ;
             count += n;
         }
         return  count;
     }

     /**
      * Copy chars from a <code>Reader</code> to a <code>Writer</code>.
      @param  input the <code>Reader</code> to read from
      @param  output the <code>Writer</code> to write to
      @return  the number of characters copied
      @throws  IOException In case of an I/O problem
      */
     public static  int  copy ( Reader input, Writer output throws  IOException
     {
         char []  buffer =  new  char [ DEFAULT_BUFFER_SIZE ] ;
         int  count =  0 ;
         int  n =  0 ;
         while  ( - !=  ( n = input.read ( buffer )))
         {
             output.write ( buffer,  0 , n ) ;
             count += n;
         }
         return  count;
     }

     /**
      * Copy and convert bytes from an <code>InputStream</code> to chars on a
      * <code>Writer</code>.
      * The platform's default encoding is used for the byte-to-char conversion.
      @param  input the <code>InputStream</code> to read from
      @param  output the <code>Writer</code> to write to
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( InputStream input, Writer output throws  IOException
     {
         InputStreamReader in =  new  InputStreamReader ( input ) ;
         copy ( in, output ) ;
     }

     /**
      * Copy and convert bytes from an <code>InputStream</code> to chars on a
      * <code>Writer</code>, using the specified encoding.
      @param  input the <code>InputStream</code> to read from
      @param  output the <code>Writer</code> to write to
      @param  encoding The name of a supported character encoding. See the
      * <a href="http://www.iana.org/assignments/character-sets">IANA
      * Charset Registry</a> for a list of valid encoding types.
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( InputStream input, Writer output, String encoding throws  IOException
     {
         InputStreamReader in =  new  InputStreamReader ( input, encoding ) ;
         copy ( in, output ) ;
     }

     /**
      * Serialize chars from a <code>Reader</code> to bytes on an
      * <code>OutputStream</code>, and flush the <code>OutputStream</code>.
      @param  input the <code>Reader</code> to read from
      @param  output the <code>OutputStream</code> to write to
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( Reader input, OutputStream output throws  IOException
     {
         OutputStreamWriter out =  new  OutputStreamWriter ( output ) ;
         copy ( input, out ) ;
         // XXX Unless anyone is planning on rewriting OutputStreamWriter, we have to flush here.
         out.flush () ;
     }

     /**
      * Serialize chars from a <code>String</code> to bytes on an <code>OutputStream</code>, and
      * flush the <code>OutputStream</code>.
      @param  input the <code>String</code> to read from
      @param  output the <code>OutputStream</code> to write to
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( String input, OutputStream output throws  IOException
     {
         StringReader in =  new  StringReader ( input ) ;
         OutputStreamWriter out =  new  OutputStreamWriter ( output ) ;
         copy ( in, out ) ;
         // XXX Unless anyone is planning on rewriting OutputStreamWriter, we have to flush here.
         out.flush () ;
     }

     /**
      * Copy chars from a <code>String</code> to a <code>Writer</code>.
      @param  input the <code>String</code> to read from
      @param  output the <code>Writer</code> to write to
      @throws  IOException In case of an I/O problem
      */
     public static  void  copy ( String input, Writer output throws  IOException
     {
         output.write ( input ) ;
     }

     /**
      * The name says it all.
      */
     private static final  int  DEFAULT_BUFFER_SIZE =  1024  4 ;
}
【SCI复现】含可再生能源与储能的区域微电网最优运行:应对不确定性的解鲁棒性与非预见性研究(Matlab代码实现)内容概要:本文围绕含可再生能源与储能的区域微电网最优运行展开研究,重点探讨应对不确定性的解鲁棒性与非预见性策略,通过Matlab代码实现SCI论文复现。研究涵盖多阶段鲁棒调度模型、机会约束规划、需求响应机制及储能系统优化配置,结合风电、光伏等可再生能源出力的不确定性建模,提出兼顾系统经济性与鲁棒性的优化运行方案。文中详细展示了模型构建、算法设计(如C&CG算法、大M法)及仿真验证全过程,适用于微电网能量管理、电力系统优化调度等领域的科研与工程实践。; 适合人群:具备一定电力系统、优化理论和Matlab编程基础的研究生、科研人员及从事微电网、能源管理相关工作的工程技术人员。; 使用场景及目标:①复现SCI级微电网鲁棒优化研究成果,掌握应对风光负荷不确定性的建模与求解方法;②深入理解两阶段鲁棒优化、分布鲁棒优化、机会约束规划等先进优化方法在能源系统中的实际应用;③为撰写高水平学术论文或开展相关课题研究提供代码参考和技术支持。; 阅读建议:建议读者结合文档提供的Matlab代码逐模块学习,重点关注不确定性建模、鲁棒优化模型构建与求解流程,并尝试在不同场景下调试与扩展代码,以深化对微电网优化运行机制的理解。
个人防护装备实例分割数据集 一、基础信息 数据集名称:个人防护装备实例分割数据集 图片数量: 训练集:4,524张图片 分类类别: - Gloves(手套):工作人员佩戴的手部防护装备。 - Helmet(安全帽):头部防护装备。 - No-Gloves(未戴手套):未佩戴手部防护的状态。 - No-Helmet(未戴安全帽):未佩戴头部防护的状态。 - No-Shoes(未穿安全鞋):未佩戴足部防护的状态。 - No-Vest(未穿安全背心):未佩戴身体防护的状态。 - Shoes(安全鞋):足部防护装备。 - Vest(安全背心):身体防护装备。 标注格式:YOLO格式,包含实例分割的多边形坐标和类别标签,适用于实例分割任务。 数据格式:来源于实际场景图像,适用于计算机视觉模型训练。 二、适用场景 工作场所安全监控系统开发:数据集支持实例分割任务,帮助构建能够自动识别工作人员个人防护装备穿戴状态的AI模型,提升工作环境安全性。 建筑与工业安全检查:集成至监控系统,实时检测PPE穿戴情况,预防安全事故,确保合规性。 学术研究与创新:支持计算机视觉在职业安全领域的应用研究,促进AI与安全工程的结合。 培训与教育:可用于安全培训课程,演示PPE识别技术,增强员工安全意识。 三、数据集优势 精准标注与多样性:每个实例均用多边形精确标注,确保分割边界准确;覆盖多种PPE物品及未穿戴状态,增加模型鲁棒性。 场景丰富:数据来源于多样环境,提升模型在不同场景下的泛化能力。 任务适配性强:标注兼容主流深度学习框架(如YOLO),可直接用于实例分割模型开发,支持目标检测和分割任务。 实用价值高:专注于工作场所安全,为自动化的PPE检测提供可靠数据支撑,有助于减少工伤事故。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值