-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #35 from swismer/resources-rebuild-support
Resources rebuild support
- Loading branch information
Showing
21 changed files
with
572 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 0 additions & 27 deletions
27
src/main/java/com/kichik/pecoff4j/RebuildableStructure.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package com.kichik.pecoff4j; | ||
|
||
import com.kichik.pecoff4j.io.DataWriter; | ||
import com.kichik.pecoff4j.io.IDataWriter; | ||
import com.kichik.pecoff4j.util.PaddingType; | ||
|
||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
|
||
/** | ||
* A structure that can be written using a data writer. | ||
*/ | ||
public interface WritableStructure { | ||
/** | ||
* Write this structure to a data writer. | ||
* | ||
* @param dw the writer | ||
*/ | ||
void write(IDataWriter dw) throws IOException; | ||
|
||
/** | ||
* Write this structure to a byte array using {@link PaddingType#PATTERN} and no alignment. | ||
* @return the byte array | ||
*/ | ||
default byte[] toByteArray() { | ||
return toByteArray(PaddingType.PATTERN, 1); | ||
} | ||
/** | ||
* Write this structure to a byte array. | ||
* @param paddingType the padding mode | ||
* @param alignment the alignment to use after writing this structure | ||
* @return the byte array | ||
*/ | ||
default byte[] toByteArray(PaddingType paddingType, int alignment) { | ||
try { | ||
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | ||
DataWriter writer = new DataWriter(baos); | ||
writer.setPaddingMode(paddingType); | ||
write(writer); | ||
writer.align(alignment); | ||
writer.close(); | ||
return baos.toByteArray(); | ||
} catch (IOException e) { | ||
// cannot happen due to in-memory implementation of writer | ||
throw new RuntimeException("DataWriter must not throw IOException when using ByteArrayOutputStream"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.