private static Decoder getDecoder(final String pCharset) { // NOTE: The CharsetDecoder is typically 10-20% faster than // StringDecoder according to my tests // StringEncoder is horribly slow on 1.2 systems, but there's no // alternative... if (NIO_AVAILABLE) { return new CharsetDecoder(pCharset); } return new StringDecoder(pCharset); }
@Override public final void write(byte[] pBytes, int pOffset, int pLength) throws IOException { flushBuffer(); decoder.decodeTo(writer, pBytes, pOffset, pLength); }
/** * Gets the file (type) extension of the given file. * A file extension is the part of the filename, after the last occurence * of a period {@code '.'}. * If the filename contains no period, {@code null} is returned. * * @param pFileName the full filename with extension * @return the extension (type) of the file, or {@code null} */ public static String getExtension(final String pFileName) { return getExtension0(getFilename(pFileName)); }
protected final void syncPosition() throws IOException { if (cache.getPosition() != position) { cache.seek(position); // Assure EOF is correctly thrown } }
public static long getTotalSpace(final File pPath) { // NOTE: Allow null, to get space in current/system volume File path = pPath != null ? pPath : new File("."); Long space = getSpace16("getTotalSpace", path); if (space != null) { return space; } return FS.getTotalSpace(path); }
/** * Creates a read only {@code CompoundDocument}. * * @param pInput the input to read from. * * @throws IOException if an I/O exception occurs while reading the header */ public CompoundDocument(final InputStream pInput) throws IOException { this(new MemoryCacheSeekableStream(pInput)); }
protected SeekableInputStream makeInputStream(final InputStream pStream) { try { return new FileSeekableStream(createFileWithContent(pStream)); } catch (IOException e) { throw new RuntimeException(e); } }
/** * Extracts the directory path without the filename, from a complete * filename path. * * @param pPath The full filename path. * @return the path without the filename. * @see File#getParent * @see #getFilename */ public static String getDirectoryname(final String pPath) { return getDirectoryname(pPath, File.separatorChar); }
/** * Deletes the specified file. * * @param pFile The file to delete * @return {@code true}, if the file existed and was deleted. * @throws java.io.IOException if deletion fails */ public static boolean delete(File pFile) throws IOException { return delete(pFile, false); }
/*protected*/ FileCacheSeekableStream(final InputStream pStream, final File pFile) throws FileNotFoundException { super(pStream, new FileCache(pFile)); // TODO: Allow for custom buffer sizes? buffer = new byte[1024]; }
public void write(final int pByte) throws IOException { byte[] buffer = getBlock(); int idx = (int) (position % BLOCK_SIZE); buffer[idx] = (byte) pByte; position++; if (position > length) { length = position; } }
/** * Lists all files (and directories) in a specific folder. * * @param pFolder The folder to list * @return a list of {@code java.io.File} objects. * @throws FileNotFoundException if {@code pFolder} is not a readable file */ public static File[] list(final String pFolder) throws FileNotFoundException { return list(pFolder, null); }
@Override public void write(int pByte) { int newCount = count + 1; growIfNeeded(newCount); buf[count] = (byte) pByte; count = newCount; }
long getFreeSpace(File pPath) { try { return getNumber(pPath, 3); } catch (IOException e) { return 0l; } }
/** * Marks this stream as closed. * This implementation does <em>not</em> close the underlying stream. */ @Override public void close() throws IOException { // NOTE: Do not close the underlying stream while (bytesLeft > 0) { //noinspection ResultOfMethodCallIgnored skip(bytesLeft); } }
@Override public int read(byte pBytes[], int pOffset, int pLength) throws IOException { return mStream.read(pBytes, pOffset, pLength); } }
long getTotalSpace(File pPath) { // TODO: Implement, probably need some JNI stuff... // Distribute df.exe and execute from temp!? ;-) return getFreeSpace(pPath); }