【Stream】//数据源:数组/Collection
01 串行流
Collection.stream()
Stream.of(...)
02 并行流
Collection.parallelStream()
Stream.of(...).parallelStreeam()
01 void forEach (Consumer<? super T> action)
02 Stream<T> filter(Predicate<? super T> predicate)
03 <R> Stream<R> map(Function<? super T,? extends R> mapper)
04 long count()
05 Stream<T> limit(long maxSize)
06 Stream<T> skip(long n)
07 static <T> Stream<T> concat(Stream<? extends T> a,Stream<?
extends T> b)
01 collect(Collector c)
01 Collectors.toList()
02 Collectors.toSet()
02 toArray(IntFunction g) //String[]::new
【方法引用】//::
01 对象名引用成员变量
02 类名称引用静态方法
03 super引用成员变量
04 this引用成员方法
05 类的构造器引用
06 数组的构造器引用
【java.util.function】
public interface Supplier<T>
T get();
//提供一个数据
public interface Consumer<T>
void accept(T t)
//接收一个数据
Consumer<T> andThen(Consumer<? super T> after)
pulbic interface Predicate<T>
boolean test(T t)
//测试传入的数据是否满足要求
Predicate<T> and(Predicate<? super T> other)
Predicate<T> negate()
//取反
Predicate<T> or(Predicate<? super T> other)
public interface Function<T, R>
R apply(T t)
//接收数据,返回结果
<V> Function<V, R> compose(Function<? super V, ? extends T>
before)
<V> Function<T, V> andThen(Function<? super R, ? extends V>
after)
<T> Function<T, T> identity()
//a function that always returns its input argument
interface Object中的方法【待完成】
C/S
B/S
TCP/IP
TCP
UDP
协议 IP 端口号
IPv4 32位
IPv6 128位
端口号 0-65535 0-1023,被电脑占用
java.net.Socket
Socket(String host,int port)
InputStream getInputStream()
read() 【阻塞】
OutputStream getOutputStream()
close()
shutdownOutput()
java.net.ServerSocket
ServerSocket(int port)
Socket accept() 【阻塞】
缓冲流
BufferedInputStream
BufferedOutputStream
BUfferedReader readLine()
BUfferedWriter newLine()
字符编码与字符集
GBK
ISO-8859-1
UTF-8
转换流
InputStreamReader
InputStreamReader(InputStream in,String charsetName)
OutputStreamWriter
OutputStreamWriter(OutputStream in,String charsetName)
序列化 对象 -> 字节
反序列化 字节 -> 对象
被 static 修饰的属性不能被序列化
java.io.Serializable
不需要进行序列化的属性,可以使用 transient 修饰
//防止出现 InvalidClassException
static final long serialVersionUID = 1L;
对象流
ObjectOutputStream
ObjectInputStream
IO
OutputStream //末尾,不追加 追加
close()
flush()
write(byte[] b)
write(byte[] b,int off,int len)
InputStream
close()
int read() 从输入流读取数据的下一个【字节】
int read(byte[] b) 从输入流中读取一些字节,并将它们存储
到字节数组 b中
Reader
close()
int read() 从输入流读取数据的下一个【字符】
int read(char[] cbuf) 从输入流中读取一些字符,并将它们存
储到字符数组
Writer //末尾,不追加 追加
write(int c)
write(char[] cbuf)
write(char[] cbuf,int off,int len)
write(String str)
write(String str,int off,int len)
输入输出流关闭顺序:先关闭输出流,再关闭输入流
原因:如果先关闭输入流,可能会丢失最后的几个数据
Properties
load(InputStream in)
store(OuputStream out,String comments)
IO异常处理机制
01 try{]catch(IOException e){}finally{}
02 try(FileInputStream fis1 = new FileInputStream
(file);FileInputStream fis2 = new FileInputStream(file);)
{}catch(IOException e){}
03
final FileInputStream fis1 = new FileInputStream
(file);FileInputStream fis2 = new FileInputStream(file);
try(fis1;fis2){}catch(IOException e){}
|
|