@PrivateApi public final class IOUtil extends Object
Modifier and Type | Field and Description |
---|---|
static byte |
PRIMITIVE_TYPE_BOOLEAN |
static byte |
PRIMITIVE_TYPE_BYTE |
static byte |
PRIMITIVE_TYPE_DOUBLE |
static byte |
PRIMITIVE_TYPE_FLOAT |
static byte |
PRIMITIVE_TYPE_INTEGER |
static byte |
PRIMITIVE_TYPE_LONG |
static byte |
PRIMITIVE_TYPE_SHORT |
static byte |
PRIMITIVE_TYPE_UTF |
Modifier and Type | Method and Description |
---|---|
static void |
close(Connection conn,
String reason) |
static void |
close(ServerSocket serverSocket)
Quietly attempts to close a
ServerSocket , swallowing any exception. |
static void |
close(Socket socket)
Quietly attempts to close a
Socket , swallowing any exception. |
static void |
closeResource(Closeable closeable)
Quietly attempts to close a
Closeable resource, swallowing any exception. |
static void |
compactOrClear(ByteBuffer bb)
Compacts or clears the buffer depending if bytes are remaining in the byte-buffer.
|
static byte[] |
compress(byte[] input) |
static void |
copy(File source,
File target)
Deep copies source to target and creates the target if necessary.
|
static void |
copy(InputStream source,
File target)
Deep copies source to target.
|
static void |
copyFile(File source,
File target,
long sourceCount)
Copies source file to target and creates the target if necessary.
|
static int |
copyToHeapBuffer(ByteBuffer src,
ByteBuffer dst) |
static byte[] |
decompress(byte[] compressedData) |
static void |
delete(File f)
Ensures that the file described by the supplied parameter does not exist
after the method returns.
|
static void |
deleteQuietly(File f)
Ensures that the file described by the supplied parameter does not exist
after the method returns.
|
static void |
drainTo(InputStream input,
OutputStream output) |
static File |
getFileFromResources(String resourceFileName) |
static InputStream |
getFileFromResourcesAsStream(String resourceFileName) |
static String |
getPath(String... parts)
Concatenates path parts to a single path using the
File.separator where it applies. |
static ByteBuffer |
newByteBuffer(int bufferSize,
boolean direct) |
static InputStream |
newInputStream(ByteBuffer src) |
static ObjectInputStream |
newObjectInputStream(ClassLoader classLoader,
ClassNameFilter classFilter,
InputStream in) |
static OutputStream |
newOutputStream(ByteBuffer dst) |
static Object |
readAttributeValue(ObjectDataInput in) |
static byte[] |
readByteArray(ObjectDataInput in) |
static void |
readFully(InputStream in,
byte[] buffer)
Fills a buffer from an
InputStream . |
static boolean |
readFullyOrNothing(InputStream in,
byte[] buffer)
Fills a buffer from an
InputStream . |
static <T> T |
readObject(ObjectDataInput in) |
static void |
rename(File fileNow,
File fileToBe)
Ensures that the file described by
fileNow is renamed to file described by fileToBe . |
static void |
setChannelOptions(Channel channel,
EndpointConfig config)
Sets configured channel options on given
Channel . |
static byte[] |
toByteArray(InputStream is) |
static String |
toDebugString(String name,
ByteBuffer byteBuffer)
Creates a debug String for te given ByteBuffer.
|
static String |
toFileName(String name) |
static void |
touch(File file)
Simulates a Linux
touch command, by setting the last modified time of given file. |
static void |
writeAttributeValue(Object value,
ObjectDataOutput out) |
static void |
writeByteArray(ObjectDataOutput out,
byte[] value) |
static void |
writeObject(ObjectDataOutput out,
Object object) |
public static final byte PRIMITIVE_TYPE_BOOLEAN
public static final byte PRIMITIVE_TYPE_BYTE
public static final byte PRIMITIVE_TYPE_SHORT
public static final byte PRIMITIVE_TYPE_INTEGER
public static final byte PRIMITIVE_TYPE_LONG
public static final byte PRIMITIVE_TYPE_FLOAT
public static final byte PRIMITIVE_TYPE_DOUBLE
public static final byte PRIMITIVE_TYPE_UTF
public static void compactOrClear(ByteBuffer bb)
bb
- the ByteBufferpublic static ByteBuffer newByteBuffer(int bufferSize, boolean direct)
public static void writeByteArray(ObjectDataOutput out, byte[] value) throws IOException
IOException
public static byte[] readByteArray(ObjectDataInput in) throws IOException
IOException
public static void writeObject(ObjectDataOutput out, Object object) throws IOException
IOException
public static <T> T readObject(ObjectDataInput in) throws IOException
IOException
public static boolean readFullyOrNothing(InputStream in, byte[] buffer) throws IOException
InputStream
. If it doesn't contain any
more data, returns false
. If it contains some data, but not
enough to fill the buffer, EOFException
is thrown.in
- the InputStream
to read frombuffer
- the buffer to filltrue
if the buffer was filled completely,
false
if there was no data in the InputStream
EOFException
- if there was some, but not enough, data in the
InputStream
to fill the bufferIOException
public static void readFully(InputStream in, byte[] buffer) throws IOException
InputStream
.in
- the InputStream
to read frombuffer
- the buffer to fillEOFException
- if there was not enough data in the InputStream
to fill the bufferIOException
public static ObjectInputStream newObjectInputStream(ClassLoader classLoader, ClassNameFilter classFilter, InputStream in) throws IOException
IOException
public static OutputStream newOutputStream(ByteBuffer dst)
public static InputStream newInputStream(ByteBuffer src)
public static int copyToHeapBuffer(ByteBuffer src, ByteBuffer dst)
public static byte[] compress(byte[] input)
public static byte[] decompress(byte[] compressedData)
public static void writeAttributeValue(Object value, ObjectDataOutput out) throws IOException
IOException
public static Object readAttributeValue(ObjectDataInput in) throws IOException
IOException
public static void closeResource(Closeable closeable)
Closeable
resource, swallowing any exception.closeable
- the resource to close. If null
, no action is taken.public static void close(Connection conn, String reason)
public static void close(ServerSocket serverSocket)
ServerSocket
, swallowing any exception.serverSocket
- server socket to close. If null
, no action is taken.public static void close(Socket socket)
Socket
, swallowing any exception.socket
- socket to close. If null
, no action is taken.public static void deleteQuietly(File f)
public static void delete(File f)
public static void rename(File fileNow, File fileToBe)
fileNow
is renamed to file described by fileToBe
.
First attempts to perform a direct, atomic rename; if that fails, checks whether the target exists,
deletes it, and retries. Throws an exception in each case where the rename failed.fileNow
- describes an existing filefileToBe
- describes the desired pathname for the filepublic static String getPath(String... parts)
File.separator
where it applies.
There is no validation done on the newly formed path.parts
- The path parts that together should form a pathIllegalArgumentException
- if the parts param is null or emptypublic static InputStream getFileFromResourcesAsStream(String resourceFileName)
public static void touch(File file)
touch
command, by setting the last modified time of given file.file
- the file to touchpublic static void copy(File source, File target)
The source can be a directory or a file and the target can be a directory or file.
If the source is a directory, it expects that the target is a directory (or that it doesn't exist) and nests the copied source under the target directory.
source
- the sourcetarget
- the destinationIllegalArgumentException
- if the source was not found or the source is a directory and the target is a fileHazelcastException
- if there was any exception while creating directories or copyingpublic static void copy(InputStream source, File target)
HazelcastException
.
The source is only accessed here, but not managed. It's the responsibility of the caller to release any resources hold by the source.
source
- the sourcetarget
- the destinationHazelcastException
- if the target doesn't existpublic static void copyFile(File source, File target, long sourceCount)
source
- the source filetarget
- the destination file or directorysourceCount
- the maximum number of bytes to be transferred (if negative transfers the entire source file)IllegalArgumentException
- if the source was not found or the source not a fileHazelcastException
- if there was any exception while creating directories or copyingpublic static byte[] toByteArray(InputStream is) throws IOException
IOException
public static void drainTo(InputStream input, OutputStream output) throws IOException
IOException
public static String toDebugString(String name, ByteBuffer byteBuffer)
Do not remove even if this method isn't used.
name
- name of the ByteBuffer.byteBuffer
- the ByteBufferpublic static void setChannelOptions(Channel channel, EndpointConfig config)
Channel
.channel
- the Channel
on which options will be setconfig
- the endpoint configurationCopyright © 2022 Hazelcast, Inc.. All Rights Reserved.