2727import java .util .Optional ;
2828import java .util .Set ;
2929import java .util .TreeMap ;
30- import java .util .function .Function ;
3130import java .util .function .IntFunction ;
3231import java .util .stream .IntStream ;
3332
4746import org .eclipse .packager .rpm .parse .RpmInputStream ;
4847
4948public class Dumper {
50- private static final Boolean SKIP_META = Boolean .getBoolean ("skipMeta" );
49+ private static final boolean SKIP_META = Boolean .getBoolean ("skipMeta" );
5150
52- private static final Boolean SKIP_SIGNATURES = Boolean .getBoolean ("skipSignatures" );
51+ private static final boolean SKIP_SIGNATURES = Boolean .getBoolean ("skipSignatures" );
5352
54- private static final Boolean SKIP_HEADERS = Boolean .getBoolean ("skipHeaders" );
53+ private static final boolean SKIP_HEADERS = Boolean .getBoolean ("skipHeaders" );
5554
56- private static final Boolean SKIP_PAYLOAD = Boolean .getBoolean ("skipPayload" );
55+ private static final boolean SKIP_PAYLOAD = Boolean .getBoolean ("skipPayload" );
56+
57+ private static final boolean SORTED = Boolean .getBoolean ("sorted" );
5758
5859 public static String dumpFlag (final int value , final IntFunction <Optional <?>> func ) {
5960 final Optional <?> flag = func .apply (value );
60-
61- if (flag .isPresent ()) {
62- return String .format ("%s (%s)" , flag .get (), value );
63- } else {
64- return String .format ("%s" , value );
65- }
61+ return flag .map (o -> String .format ("%s (%s)" , o , value )).orElseGet (() -> String .format ("%s" , value ));
6662 }
6763
6864 public static void dumpAll (final RpmInputStream in ) throws IOException {
@@ -76,10 +72,10 @@ public static void dumpAll(final RpmInputStream in) throws IOException {
7672 }
7773
7874 if (!SKIP_SIGNATURES ) {
79- dumpHeader ("Signature" , in .getSignatureHeader (), RpmSignatureTag ::find , false );
75+ dumpHeader ("Signature" , in .getSignatureHeader (), RpmSignatureTag ::find );
8076 }
8177 if (!SKIP_HEADERS ) {
82- dumpHeader ("Payload" , in .getPayloadHeader (), RpmTag ::find , false );
78+ dumpHeader ("Payload" , in .getPayloadHeader (), RpmTag ::find );
8379 }
8480
8581 if (!SKIP_PAYLOAD ) {
@@ -119,12 +115,12 @@ private static void dumpDeps(final String string, final List<String> names, fina
119115 IntStream .range (0 , names .size ()).forEach (i -> System .out .format ("%s: %s - %s - %s %s%n" , string , names .get (i ), versions .get (i ), flags .get (i ), RpmDependencyFlags .parse (flags .get (i ))));
120116 }
121117
122- private static void dumpHeader (final String string , final InputHeader <? extends RpmBaseTag > header , final Function < Integer , RpmBaseTag > func , final boolean sorted ) {
123- System .out .format (string + "%n" );
124- System .out .format ("=================================%n " );
118+ private static void dumpHeader (final String string , final InputHeader <? extends RpmBaseTag > header , final IntFunction < RpmBaseTag > func ) {
119+ System .out .println (string );
120+ System .out .println ("=================================" );
125121
126122 Set <Entry <Integer , HeaderValue <?>>> data ;
127- if (sorted ) {
123+ if (SORTED ) {
128124 data = new TreeMap <>(header .getRawTags ()).entrySet ();
129125 } else {
130126 data = header .getRawTags ().entrySet ();
@@ -148,7 +144,7 @@ private static void dumpEntry(final CpioArchiveEntry entry) {
148144 System .out .format (" Size: %s, Chksum: %016x, Align: %s, Inode: %016x, Mode: %08o, NoL: %s, Device: %s.%s%n" , entry .getSize (), entry .getChksum (), entry .getAlignmentBoundary (), entry .getInode (), entry .getMode (), entry .getNumberOfLinks (), entry .getDeviceMaj (), entry .getDeviceMin ());
149145 }
150146
151- public static void main (final String [] args ) throws IOException {
147+ public static void main (final String [] args ) {
152148 for (final String file : args ) {
153149 dump (Path .of (file ));
154150 }
0 commit comments