# Class: com.pnfsoftware.jeb.core.units.code.DecompilerExporter

Helper class used to decompile and export to source files all or a subset of classes or methods of a code unit. 

 Example: export all top\-level items to an output folder: 

```

 IDecompilerUnit decomp = ...; // retrieved from the current IRuntimeProject
 File outdir = ...;
 DecompilerExporter exp = decomp.getExporter();
 exp.setOutputFolder(outdir, false);
 exp.setMethodTimeout(60_000L);  // safety
 exp.setTotalTimeout(15 * 60_000L);  // safety
 exp.setCallback(new ProgressCallbackAdapter() {
     @Override
     public void message(String msg) {
         System.out.println(msg);
     }
 });
 boolean success = exp.process();
 System.out.println("Errors: " + exp.getErrors());
 
```

## Constructor: DecompilerExporter
- parameter: `decompiler`, type: `com.pnfsoftware.jeb.core.units.code.IDecompilerUnit`

Description: Create an exporter with default settings.
parameter: decompiler: a decompiler

## Protected Field: callback
Type: `com.pnfsoftware.jeb.util.base.IProgressCallback`
Description: Progress callback.

## Protected Field: decomp
Type: `com.pnfsoftware.jeb.core.units.code.IDecompilerUnit`
Description: Decompiler unit.

## Protected Field: discardDecompiledItemsAfterProcessing
Type: `boolean`
Description: True to discard decompiled items after processing.

## Protected Field: errormap
Type: `java.util.Map<java.lang.String,java.lang.String>`
Description: Decompilation errors.

## Protected Field: headerString
Type: `java.lang.String`
Description: Header prepended to generated files.

## Protected Field: methodTimeoutMs
Type: `long`
Description: Per\-method timeout, in milliseconds.

## Protected Field: outputFolder
Type: `java.io.File`
Description: Output folder.

## Protected Field: pattern
Type: `java.util.regex.Pattern`
Description: Optional signature pattern.

## Protected Field: totalTimeoutMs
Type: `long`
Description: Total timeout, in milliseconds.

## Protected Field: usesCustomDecompWriter
Type: `boolean`
Description: True if a custom decompilation writer is used.

## Protected Field: writeCount
Type: `java.util.concurrent.atomic.AtomicInteger`
Description: Generated file count.

## Protected Field: writeErrorCount
Type: `java.util.concurrent.atomic.AtomicInteger`
Description: Generated file error count.

## Protected Static Field: logger
Type: `com.pnfsoftware.jeb.util.logging.ILogger`
Description: Logger.

## Protected Method: customizeOptions
- parameter: `decompilingClasses`, type: `boolean`
- parameter: `optbld`, type: `com.pnfsoftware.jeb.core.units.code.DecompilationOptions.Builder`

Description: Optional method used to customize the options of the decompilation context. The custom implementation may modify or set new options. The default implementation does nothing.
parameter: decompilingClasses: true if the exporter will decompile classes; false if it will            decompile methods
parameter: optbld: the current option builder

## Method: export
- return type: `boolean`

Description: A synonym for [#process()](#process()).
return: true if no error occurred

## Protected Method: generateClassFileName
- parameter: `address`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Generate a file name for a decompiled class.
parameter: address: class address
return: file name

## Protected Method: generateMethodFileName
- parameter: `address`, type: `java.lang.String`
- return type: `java.lang.String`

Description: Generate a file name for a decompiled method.
parameter: address: method address
return: file name

## Method: getCallback
- return type: `com.pnfsoftware.jeb.util.base.IProgressCallback`

Description: Get the progress callback.
return: progress callback, or null

## Method: getDecompiler
- return type: `com.pnfsoftware.jeb.core.units.code.IDecompilerUnit`

Description: Get the decompiler.
return: decompiler

## Method: getErrors
- return type: `java.util.Map<java.lang.String,java.lang.String>`

Description: Retrieve a map "address \-\> error string" for all methods that failed the decompilation. Call after [#process()](#process()).
return: error map

## Method: getGeneratedFileCount
- return type: `java.lang.Integer`

Description: Retrieve the number of generated source files.
return: generated file count

## Method: getHeaderString
- return type: `java.lang.String`

Description: Get the header string prepended to generated files.
return: header string, or null

## Method: getMethodTimeout
- return type: `long`

Description: Get the method timeout.
return: timeout in milliseconds

## Method: getOutputFolder
- return type: `java.io.File`

Description: Get the output folder.
return: output folder, or null

## Method: getSignaturePattern
- return type: `java.util.regex.Pattern`

Description: Get the signature pattern.
return: signature pattern, or null

## Method: getTotalTimeout
- return type: `long`

Description: Get the total timeout.
return: timeout in milliseconds

## Method: isDiscardDecompiledItemsAfterProcessing
- return type: `boolean`

Description: Determine whether decompiled items are discarded after processing.
return: true if decompiled items are discarded after processing

## Method: process
- return type: `boolean`

Description: Decompile and export all meaningful elements. This is the recommended method to call. Top\-level classes and their constituents will be exported; orphaned methods and other items will be exported as well. 

 If an output folder was specified, the resulting source files will be stored in a folder hierarchy that matches their namespace or package name.
return: true if no error occurred; false if some errors occurred

## Method: processMethods
- return type: `boolean`

Description: Decompile and export all internal methods. Refer to [#processTopLevelClasses()](#processTopLevelClasses()) to export classes hierarchically. 

 If an output folder was specified, the resulting source files will be stored in that folder. No folder hierarchy is created. File names are uniquely derived from method signatures.
return: true if no error occurred; false if some errors occurred

## Method: processTopLevelClasses
- return type: `boolean`

Description: Decompile and export all top\-level classes \(i.e., non member classes\). 

 If an output folder was specified, the resulting source files will be stored in a folder hierarchy that matches their namespace or package name.
return: true if no error occurred; false if some errors occurred

## Protected Method: reset

Description: Reset exporter counters and errors.

## Method: setCallback
- parameter: `callback`, type: `com.pnfsoftware.jeb.util.base.IProgressCallback`

Description: Set an optional callback to receive progress information on the decompilation.
parameter: callback: progress callback

## Method: setDiscardDecompiledItemsAfterProcessing
- parameter: `discardDecompiledItemsAfterProcessing`, type: `boolean`

Description: Specify whether decompiled items should be kept or discarded after the decompilation process is complete. Unless you are planning to examine decompiled items later, it is recommended to discard them.
parameter: discardDecompiledItemsAfterProcessing: true to discard decompiled items after processing

## Method: setHeaderString
- parameter: `s`, type: `java.lang.String`

Description: Set an optional single\-line header string, prepended to all decompiled classes. The default header string is: `Decompiled by JEB v[VERSION] `
parameter: s: header string

## Method: setMethodTimeout
- parameter: `methodTimeoutMs`, type: `long`

Description: Set an optional timeout for method decompilation.
parameter: methodTimeoutMs: timeout in milliseconds

## Method: setOutputFolder
- parameter: `folder`, type: `java.io.File`

Description: Set the output folder.
parameter: folder: output folder
throws: if the output folder cannot be created

## Method: setOutputFolder
- parameter: `folder`, type: `java.io.File`
- parameter: `discardDecompiledItemsAfterProcessing`, type: `java.lang.Boolean`

Description: Set an optional output folder. If the folder exists and contents is already present, it will NOT be removed.
parameter: folder: output folder
parameter: discardDecompiledItemsAfterProcessing: optional; if non\-null, also update            [#setDiscardDecompiledItemsAfterProcessing(boolean)](#setDiscardDecompiledItemsAfterProcessing(boolean))
throws: if some error occurred when creating the output folder

## Method: setSignaturePattern
- parameter: `pattern`, type: `java.util.regex.Pattern`

Description: Set an optional matcher for classes or methods to be decompiled.
parameter: pattern: a regex pattern

## Method: setTotalTimeout
- parameter: `totalTimeoutMs`, type: `long`

Description: Set an optional timeout for the entire decompilation process.
parameter: totalTimeoutMs: timeout in milliseconds

## Protected Method: writeClassDecompilation
- parameter: `addr`, type: `java.lang.String`

Description: Write a class decompilation to disk.
parameter: addr: class address

## Protected Method: writeMethodDecompilation
- parameter: `addr`, type: `java.lang.String`

Description: Write a method decompilation to disk.
parameter: addr: method address

