summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2023-05-04 16:07:44 +0200
committerSimon Rettberg2023-05-04 16:07:44 +0200
commitd7b762835fff6b2ff12cd570da70a8d7eaae216b (patch)
tree9704f2836f337e88f289cff7dfcfc1cfe7a371aa
parent[libvirt] Reintroduce a very basic sanity check in Domain constructor (diff)
downloadmaster-sync-shared-d7b762835fff6b2ff12cd570da70a8d7eaae216b.tar.gz
master-sync-shared-d7b762835fff6b2ff12cd570da70a8d7eaae216b.tar.xz
master-sync-shared-d7b762835fff6b2ff12cd570da70a8d7eaae216b.zip
Fix formatting
-rw-r--r--src/main/java/org/openslx/util/TarArchiveUtil.java130
1 files changed, 68 insertions, 62 deletions
diff --git a/src/main/java/org/openslx/util/TarArchiveUtil.java b/src/main/java/org/openslx/util/TarArchiveUtil.java
index d691166..9970b0b 100644
--- a/src/main/java/org/openslx/util/TarArchiveUtil.java
+++ b/src/main/java/org/openslx/util/TarArchiveUtil.java
@@ -1,9 +1,5 @@
package org.openslx.util;
-import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
-import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
-import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
-
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
@@ -14,126 +10,136 @@ import java.nio.charset.StandardCharsets;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
-public class TarArchiveUtil {
+public class TarArchiveUtil
+{
- private TarArchiveUtil() {}
+ private TarArchiveUtil()
+ {
+ }
- public static class TarArchiveReader implements AutoCloseable {
- private boolean isCompressed;
+ public static class TarArchiveReader implements AutoCloseable
+ {
private final TarArchiveInputStream tarInputStream;
private TarArchiveEntry currentEntry = null;
- public TarArchiveReader(InputStream in) throws IOException {
- this(in,true,false);
+ public TarArchiveReader( InputStream in ) throws IOException
+ {
+ this( in, true, false );
}
- public TarArchiveReader(InputStream in, boolean isBuffered, boolean isCompressed) throws IOException {
- this.isCompressed = isCompressed;
-
+ public TarArchiveReader( InputStream in, boolean isBuffered, boolean isCompressed ) throws IOException
+ {
InputStream stream = in;
- if (isBuffered) {
- stream = new BufferedInputStream(stream);
+ if ( isBuffered ) {
+ stream = new BufferedInputStream( stream );
}
- if (isCompressed) {
- stream = new GZIPInputStream(stream);
+ if ( isCompressed ) {
+ stream = new GZIPInputStream( stream );
}
- this.tarInputStream = new TarArchiveInputStream(stream);
+ this.tarInputStream = new TarArchiveInputStream( stream );
}
- public boolean hasNextEntry() throws IOException {
+ public boolean hasNextEntry() throws IOException
+ {
this.currentEntry = this.tarInputStream.getNextTarEntry();
- if (this.currentEntry != null) {
+ if ( this.currentEntry != null ) {
return true;
} else {
return false;
}
}
- public String getEntryName() {
- if (this.currentEntry == null)
+ public String getEntryName()
+ {
+ if ( this.currentEntry == null )
return null;
-
+
return this.currentEntry.getName();
}
- public byte[] readCurrentEntry() throws IOException {
+ public byte[] readCurrentEntry() throws IOException
+ {
ByteArrayOutputStream output = new ByteArrayOutputStream();
- byte[] rawData = new byte[1024];
+ byte[] rawData = new byte[ 1024 ];
int count = 0;
- while ((count = this.tarInputStream.read(rawData)) != -1) {
- output.write(rawData, 0, count);
+ while ( ( count = this.tarInputStream.read( rawData ) ) != -1 ) {
+ output.write( rawData, 0, count );
}
return output.toByteArray();
}
@Override
- public void close() throws IOException {
- tarInputStream.close();
+ public void close() throws IOException
+ {
+ tarInputStream.close();
}
-
+
}
public static class TarArchiveWriter implements AutoCloseable
{
- private boolean isBuffered;
- private boolean isCompressed;
- // private final TarOutputStream tarOutputStream;
private final TarArchiveOutputStream tarOutputStream;
-
- public TarArchiveWriter (OutputStream out) throws IOException {
- this(out, true, true);
- }
- public TarArchiveWriter (OutputStream out, boolean isBuffered, boolean isCompressed) throws IOException {
- this.isBuffered = isBuffered;
- this.isCompressed = isCompressed;
+ public TarArchiveWriter( OutputStream out ) throws IOException
+ {
+ this( out, true, true );
+ }
+ public TarArchiveWriter( OutputStream out, boolean isBuffered, boolean isCompressed ) throws IOException
+ {
OutputStream stream = out;
-
- if (isBuffered) {
- stream = new BufferedOutputStream(stream);
+
+ if ( isBuffered ) {
+ stream = new BufferedOutputStream( stream );
}
- if (isCompressed) {
- stream = new GZIPOutputStream(stream);
+ if ( isCompressed ) {
+ stream = new GZIPOutputStream( stream );
}
- this.tarOutputStream = new TarArchiveOutputStream(stream);
+ this.tarOutputStream = new TarArchiveOutputStream( stream );
}
- public void writeFile(String filename, String data) throws IOException {
+ public void writeFile( String filename, String data ) throws IOException
+ {
- if (data == null)
+ if ( data == null )
return;
- putFile(filename, data.getBytes(StandardCharsets.UTF_8));
+ putFile( filename, data.getBytes( StandardCharsets.UTF_8 ) );
}
- public void writeFile(String filename, byte[] data) throws IOException {
- if (data == null)
+ public void writeFile( String filename, byte[] data ) throws IOException
+ {
+ if ( data == null )
return;
- putFile(filename, data);
+ putFile( filename, data );
}
- private void putFile(String filename, byte[] data) throws IOException {
- if (data == null)
+ private void putFile( String filename, byte[] data ) throws IOException
+ {
+ if ( data == null )
return;
-
- TarArchiveEntry entry = new TarArchiveEntry(filename);
- entry.setSize(data.length);
- entry.setModTime(System.currentTimeMillis());
- entry.setMode(0644);
- tarOutputStream.putArchiveEntry(entry);
- tarOutputStream.write(data);
+
+ TarArchiveEntry entry = new TarArchiveEntry( filename );
+ entry.setSize( data.length );
+ entry.setModTime( System.currentTimeMillis() );
+ entry.setMode( 0644 );
+ tarOutputStream.putArchiveEntry( entry );
+ tarOutputStream.write( data );
tarOutputStream.closeArchiveEntry();
}
@Override
- public void close() throws IOException {
+ public void close() throws IOException
+ {
tarOutputStream.close();
}
}