-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathChannelHelper.java
More file actions
41 lines (35 loc) · 1.27 KB
/
ChannelHelper.java
File metadata and controls
41 lines (35 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
* Copyright (c) 2015 JRuby.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* JRuby - initial API and implementation and/or initial documentation
*/
package org.python.util;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
/**
* Helper that attempts to improve Channels' static helpers.
* @author kares
*/
public abstract class ChannelHelper {
private ChannelHelper() { /* */ }
public static ReadableByteChannel readableChannel(final InputStream inputStream) {
if ( inputStream instanceof ByteArrayInputStream ) {
if ( SeekableByteChannelImpl.USABLE ) {
return new SeekableByteChannelImpl((ByteArrayInputStream) inputStream);
}
}
return Channels.newChannel(inputStream);
}
public static WritableByteChannel writableChannel(final OutputStream ouputStream) {
return Channels.newChannel(ouputStream);
}
}