Fix code style problem in DiskUtils (#3842)
This commit is contained in:
parent
2ded5a24fc
commit
700c90d15f
@ -91,75 +91,48 @@ public final class DiskUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new empty file in the specified directory, using the given
|
* Creates a new empty file in the specified directory, using the given prefix and suffix strings to generate its
|
||||||
* prefix and suffix strings to generate its name. The resulting
|
* name. The resulting {@code Path} is associated with the same {@code FileSystem} as the given directory.
|
||||||
* {@code Path} is associated with the same {@code FileSystem} as the given
|
|
||||||
* directory.
|
|
||||||
*
|
*
|
||||||
* <p>The details as to how the name of the file is constructed is
|
* <p>The details as to how the name of the file is constructed is
|
||||||
* implementation dependent and therefore not specified. Where possible
|
* implementation dependent and therefore not specified. Where possible the {@code prefix} and {@code suffix} are
|
||||||
* the {@code prefix} and {@code suffix} are used to construct candidate
|
* used to construct candidate names in the same manner as the {@link java.io.File#createTempFile(String, String, File)}
|
||||||
* names in the same manner as the {@link
|
* method.
|
||||||
* java.io.File#createTempFile(String,String,File)} method.
|
|
||||||
*
|
*
|
||||||
*
|
* @param dir the path to directory in which to create the file
|
||||||
* @param dir
|
* @param prefix the prefix string to be used in generating the file's name; may be {@code null}
|
||||||
* the path to directory in which to create the file
|
* @param suffix the suffix string to be used in generating the file's name; may be {@code null}, in which case
|
||||||
* @param prefix
|
* "{@code .tmp}" is used
|
||||||
* the prefix string to be used in generating the file's name;
|
* @return the path to the newly created file that did not exist before this method was invoked
|
||||||
* may be {@code null}
|
* @throws IllegalArgumentException if the prefix or suffix parameters cannot be used to generate a candidate
|
||||||
* @param suffix
|
* file name
|
||||||
* the suffix string to be used in generating the file's name;
|
* @throws UnsupportedOperationException if the array contains an attribute that cannot be set atomically when
|
||||||
* may be {@code null}, in which case "{@code .tmp}" is used
|
* creating the directory
|
||||||
*
|
* @throws IOException if an I/O error occurs or {@code dir} does not exist
|
||||||
* @return the path to the newly created file that did not exist before
|
* @throws SecurityException In the case of the default provider, and a security manager is installed,
|
||||||
* this method was invoked
|
* the {@link SecurityManager#checkWrite(String) checkWrite} method is invoked
|
||||||
*
|
* to check write access to the file.
|
||||||
* @throws IllegalArgumentException
|
|
||||||
* if the prefix or suffix parameters cannot be used to generate
|
|
||||||
* a candidate file name
|
|
||||||
* @throws UnsupportedOperationException
|
|
||||||
* if the array contains an attribute that cannot be set atomically
|
|
||||||
* when creating the directory
|
|
||||||
* @throws IOException
|
|
||||||
* if an I/O error occurs or {@code dir} does not exist
|
|
||||||
* @throws SecurityException
|
|
||||||
* In the case of the default provider, and a security manager is
|
|
||||||
* installed, the {@link SecurityManager#checkWrite(String) checkWrite}
|
|
||||||
* method is invoked to check write access to the file.
|
|
||||||
*/
|
*/
|
||||||
public static File createTmpFile(String dir, String prefix, String suffix) throws IOException {
|
public static File createTmpFile(String dir, String prefix, String suffix) throws IOException {
|
||||||
return Files.createTempFile(Paths.get(dir), prefix, suffix).toFile();
|
return Files.createTempFile(Paths.get(dir), prefix, suffix).toFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an empty file in the default temporary-file directory, using
|
* Creates an empty file in the default temporary-file directory, using the given prefix and suffix to generate its
|
||||||
* the given prefix and suffix to generate its name. The resulting {@code
|
* name. The resulting {@code Path} is associated with the default {@code FileSystem}.
|
||||||
* Path} is associated with the default {@code FileSystem}.
|
|
||||||
*
|
*
|
||||||
* @param prefix
|
* @param prefix the prefix string to be used in generating the file's name; may be {@code null}
|
||||||
* the prefix string to be used in generating the file's name;
|
* @param suffix the suffix string to be used in generating the file's name; may be {@code null}, in which case
|
||||||
* may be {@code null}
|
* "{@code .tmp}" is used
|
||||||
* @param suffix
|
* @return the path to the newly created file that did not exist before this method was invoked
|
||||||
* the suffix string to be used in generating the file's name;
|
* @throws IllegalArgumentException if the prefix or suffix parameters cannot be used to generate a candidate
|
||||||
* may be {@code null}, in which case "{@code .tmp}" is used
|
* file name
|
||||||
*
|
* @throws UnsupportedOperationException if the array contains an attribute that cannot be set atomically when
|
||||||
* @return the path to the newly created file that did not exist before
|
* creating the directory
|
||||||
* this method was invoked
|
* @throws IOException if an I/O error occurs or the temporary-file directory does not exist
|
||||||
*
|
* @throws SecurityException In the case of the default provider, and a security manager is installed,
|
||||||
* @throws IllegalArgumentException
|
* the {@link SecurityManager#checkWrite(String) checkWrite} method is invoked
|
||||||
* if the prefix or suffix parameters cannot be used to generate
|
* to check write access to the file.
|
||||||
* a candidate file name
|
|
||||||
* @throws UnsupportedOperationException
|
|
||||||
* if the array contains an attribute that cannot be set atomically
|
|
||||||
* when creating the directory
|
|
||||||
* @throws IOException
|
|
||||||
* if an I/O error occurs or the temporary-file directory does not
|
|
||||||
* exist
|
|
||||||
* @throws SecurityException
|
|
||||||
* In the case of the default provider, and a security manager is
|
|
||||||
* installed, the {@link SecurityManager#checkWrite(String) checkWrite}
|
|
||||||
* method is invoked to check write access to the file.
|
|
||||||
*/
|
*/
|
||||||
public static File createTmpFile(String prefix, String suffix) throws IOException {
|
public static File createTmpFile(String prefix, String suffix) throws IOException {
|
||||||
return Files.createTempFile(prefix, suffix).toFile();
|
return Files.createTempFile(prefix, suffix).toFile();
|
||||||
@ -380,8 +353,8 @@ public final class DiskUtils {
|
|||||||
*/
|
*/
|
||||||
public static void compress(final String rootDir, final String sourceDir, final String outputFile,
|
public static void compress(final String rootDir, final String sourceDir, final String outputFile,
|
||||||
final Checksum checksum) throws IOException {
|
final Checksum checksum) throws IOException {
|
||||||
try (final FileOutputStream fos = new FileOutputStream(
|
try (final FileOutputStream fos = new FileOutputStream(outputFile);
|
||||||
outputFile); final CheckedOutputStream cos = new CheckedOutputStream(fos, checksum);
|
final CheckedOutputStream cos = new CheckedOutputStream(fos, checksum);
|
||||||
final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(cos))) {
|
final ZipOutputStream zos = new ZipOutputStream(new BufferedOutputStream(cos))) {
|
||||||
compressDirectoryToZipFile(rootDir, sourceDir, zos);
|
compressDirectoryToZipFile(rootDir, sourceDir, zos);
|
||||||
zos.flush();
|
zos.flush();
|
||||||
@ -401,8 +374,8 @@ public final class DiskUtils {
|
|||||||
compressDirectoryToZipFile(rootDir, child, zos);
|
compressDirectoryToZipFile(rootDir, child, zos);
|
||||||
} else {
|
} else {
|
||||||
zos.putNextEntry(new ZipEntry(child));
|
zos.putNextEntry(new ZipEntry(child));
|
||||||
try (final FileInputStream fis = new FileInputStream(
|
try (final FileInputStream fis = new FileInputStream(file);
|
||||||
file); final BufferedInputStream bis = new BufferedInputStream(fis)) {
|
final BufferedInputStream bis = new BufferedInputStream(fis)) {
|
||||||
IOUtils.copy(bis, zos);
|
IOUtils.copy(bis, zos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -421,16 +394,16 @@ public final class DiskUtils {
|
|||||||
*/
|
*/
|
||||||
public static void decompress(final String sourceFile, final String outputDir, final Checksum checksum)
|
public static void decompress(final String sourceFile, final String outputDir, final Checksum checksum)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
try (final FileInputStream fis = new FileInputStream(
|
try (final FileInputStream fis = new FileInputStream(sourceFile);
|
||||||
sourceFile); final CheckedInputStream cis = new CheckedInputStream(fis, checksum);
|
final CheckedInputStream cis = new CheckedInputStream(fis, checksum);
|
||||||
final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(cis))) {
|
final ZipInputStream zis = new ZipInputStream(new BufferedInputStream(cis))) {
|
||||||
ZipEntry entry;
|
ZipEntry entry;
|
||||||
while ((entry = zis.getNextEntry()) != null) {
|
while ((entry = zis.getNextEntry()) != null) {
|
||||||
final String fileName = entry.getName();
|
final String fileName = entry.getName();
|
||||||
final File entryFile = new File(Paths.get(outputDir, fileName).toString());
|
final File entryFile = new File(Paths.get(outputDir, fileName).toString());
|
||||||
FileUtils.forceMkdir(entryFile.getParentFile());
|
FileUtils.forceMkdir(entryFile.getParentFile());
|
||||||
try (final FileOutputStream fos = new FileOutputStream(
|
try (final FileOutputStream fos = new FileOutputStream(entryFile);
|
||||||
entryFile); final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
|
final BufferedOutputStream bos = new BufferedOutputStream(fos)) {
|
||||||
IOUtils.copy(zis, bos);
|
IOUtils.copy(zis, bos);
|
||||||
bos.flush();
|
bos.flush();
|
||||||
fos.getFD().sync();
|
fos.getFD().sync();
|
||||||
@ -447,11 +420,10 @@ public final class DiskUtils {
|
|||||||
/**
|
/**
|
||||||
* Returns an Iterator for the lines in a <code>File</code>.
|
* Returns an Iterator for the lines in a <code>File</code>.
|
||||||
* <p>
|
* <p>
|
||||||
* This method opens an <code>InputStream</code> for the file.
|
* This method opens an <code>InputStream</code> for the file. When you have finished with the iterator you should
|
||||||
* When you have finished with the iterator you should close the stream
|
* close the stream to free internal resources. This can be done by calling the {@link
|
||||||
* to free internal resources. This can be done by calling the
|
* org.apache.commons.io.LineIterator#close()} or {@link org.apache.commons.io.LineIterator#closeQuietly(org.apache.commons.io.LineIterator)}
|
||||||
* {@link org.apache.commons.io.LineIterator#close()} or
|
* method.
|
||||||
* {@link org.apache.commons.io.LineIterator#closeQuietly(org.apache.commons.io.LineIterator)} method.
|
|
||||||
* </p>
|
* </p>
|
||||||
* The recommended usage pattern is:
|
* The recommended usage pattern is:
|
||||||
* <pre>
|
* <pre>
|
||||||
@ -466,8 +438,7 @@ public final class DiskUtils {
|
|||||||
* }
|
* }
|
||||||
* </pre>
|
* </pre>
|
||||||
* <p>
|
* <p>
|
||||||
* If an exception occurs during the creation of the iterator, the
|
* If an exception occurs during the creation of the iterator, the underlying stream is closed.
|
||||||
* underlying stream is closed.
|
|
||||||
* </p>
|
* </p>
|
||||||
*
|
*
|
||||||
* @param file the file to open for input, must not be <code>null</code>
|
* @param file the file to open for input, must not be <code>null</code>
|
||||||
@ -486,8 +457,8 @@ public final class DiskUtils {
|
|||||||
* @param file the file to open for input, must not be <code>null</code>
|
* @param file the file to open for input, must not be <code>null</code>
|
||||||
* @return an Iterator of the lines in the file, never <code>null</code>
|
* @return an Iterator of the lines in the file, never <code>null</code>
|
||||||
* @throws IOException in case of an I/O error (file closed)
|
* @throws IOException in case of an I/O error (file closed)
|
||||||
* @since 1.3
|
|
||||||
* @see #lineIterator(File, String)
|
* @see #lineIterator(File, String)
|
||||||
|
* @since 1.3
|
||||||
*/
|
*/
|
||||||
public static LineIterator lineIterator(File file) throws IOException {
|
public static LineIterator lineIterator(File file) throws IOException {
|
||||||
return new LineIterator(FileUtils.lineIterator(file, null));
|
return new LineIterator(FileUtils.lineIterator(file, null));
|
||||||
|
@ -139,6 +139,7 @@
|
|||||||
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true"/>
|
<option name="SPACE_BEFORE_ARRAY_INITIALIZER_LBRACE" value="true"/>
|
||||||
<option name="CALL_PARAMETERS_WRAP" value="1"/>
|
<option name="CALL_PARAMETERS_WRAP" value="1"/>
|
||||||
<option name="METHOD_PARAMETERS_WRAP" value="1"/>
|
<option name="METHOD_PARAMETERS_WRAP" value="1"/>
|
||||||
|
<option name="RESOURCE_LIST_WRAP" value="2"/>
|
||||||
<option name="EXTENDS_KEYWORD_WRAP" value="1"/>
|
<option name="EXTENDS_KEYWORD_WRAP" value="1"/>
|
||||||
<option name="THROWS_KEYWORD_WRAP" value="1"/>
|
<option name="THROWS_KEYWORD_WRAP" value="1"/>
|
||||||
<option name="METHOD_CALL_CHAIN_WRAP" value="1"/>
|
<option name="METHOD_CALL_CHAIN_WRAP" value="1"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user