2222import gov .loc .repository .bagit .domain .Manifest ;
2323import gov .loc .repository .bagit .domain .Version ;
2424import gov .loc .repository .bagit .hash .Hasher ;
25+ import gov .loc .repository .bagit .util .PathUtils ;
2526import javafx .util .Pair ;
2627
2728/**
@@ -92,7 +93,7 @@ protected static Path writeVersionDependentPayloadFiles(Bag bag, Path outputDir)
9293 *
9394 * @throws IOException if there was a problem writing the file
9495 */
95- public static void writeBagitFile (Version version , String encoding , Path outputDir ) throws IOException {
96+ public static void writeBagitFile (Version version , Charset encoding , Path outputDir ) throws IOException {
9697 Path bagitPath = outputDir .resolve ("bagit.txt" );
9798 logger .debug ("Writing bagit.txt file to [{}]" , outputDir );
9899
@@ -143,7 +144,7 @@ public static void writePayloadFiles(Set<Manifest> payloadManifests, Path output
143144 *
144145 * @throws IOException if there was a problem writing a file
145146 */
146- public static void writePayloadManifests (Set <Manifest > manifests , Path outputDir , Path bagitRootDir , String charsetName ) throws IOException {
147+ public static void writePayloadManifests (Set <Manifest > manifests , Path outputDir , Path bagitRootDir , Charset charsetName ) throws IOException {
147148 logger .info ("Writing payload manifest(s)" );
148149 writeManifests (manifests , outputDir , bagitRootDir , "manifest-" , charsetName );
149150 }
@@ -178,12 +179,12 @@ protected static Set<Manifest> updateTagManifests(Bag bag, Path newBagRootDir) t
178179 *
179180 * @throws IOException if there was a problem writing a file
180181 */
181- public static void writeTagManifests (Set <Manifest > tagManifests , Path outputDir , Path bagitRootDir , String charsetName ) throws IOException {
182+ public static void writeTagManifests (Set <Manifest > tagManifests , Path outputDir , Path bagitRootDir , Charset charsetName ) throws IOException {
182183 logger .info ("Writing tag manifest(s)" );
183184 writeManifests (tagManifests , outputDir , bagitRootDir , "tagmanifest-" , charsetName );
184185 }
185186
186- protected static void writeManifests (Set <Manifest > manifests , Path outputDir , Path relativeTo , String filenameBase , String charsetName ) throws IOException {
187+ protected static void writeManifests (Set <Manifest > manifests , Path outputDir , Path relativeTo , String filenameBase , Charset charsetName ) throws IOException {
187188 for (Manifest manifest : manifests ){
188189 Path manifestPath = outputDir .resolve (filenameBase + manifest .getAlgorithm ().getBagitName () + ".txt" );
189190 logger .debug ("Writing manifest to [{}]" , manifestPath );
@@ -192,9 +193,10 @@ protected static void writeManifests(Set<Manifest> manifests, Path outputDir, Pa
192193 Files .createFile (manifestPath );
193194
194195 for (Entry <Path , String > entry : manifest .getFileToChecksumMap ().entrySet ()){
195- String line = entry .getValue () + " " + relativeTo .relativize (entry .getKey ()) + System .lineSeparator ();
196+ String line = entry .getValue () + " " +
197+ PathUtils .encodeFilename (relativeTo .relativize (entry .getKey ())) + System .lineSeparator ();
196198 logger .debug ("Writing [{}] to [{}]" , line , manifestPath );
197- Files .write (manifestPath , line .getBytes (Charset . forName ( charsetName ) ),
199+ Files .write (manifestPath , line .getBytes (charsetName ),
198200 StandardOpenOption .APPEND , StandardOpenOption .CREATE );
199201 }
200202 }
@@ -224,7 +226,7 @@ protected static void writeAdditionalTagPayloadFiles(Set<Manifest> manifests, Pa
224226 *
225227 * @throws IOException if there was a problem writing a file
226228 */
227- public static void writeBagitInfoFile (List <Pair <String , String >> metadata , Version version , Path outputDir , String charsetName ) throws IOException {
229+ public static void writeBagitInfoFile (List <Pair <String , String >> metadata , Version version , Path outputDir , Charset charsetName ) throws IOException {
228230 Path bagInfoFilePath = outputDir .resolve ("bag-info.txt" );
229231 if (VERSION_0_95 .compareTo (version ) >= 0 ){
230232 bagInfoFilePath = outputDir .resolve ("package-info.txt" );
@@ -236,7 +238,7 @@ public static void writeBagitInfoFile(List<Pair<String, String>> metadata, Versi
236238 for (Pair <String , String > entry : metadata ){
237239 String line = entry .getKey () + " : " + entry .getValue () + System .lineSeparator ();
238240 logger .debug ("Writing [{}] to [{}]" , line , bagInfoFilePath );
239- Files .write (bagInfoFilePath , line .getBytes (Charset . forName ( charsetName ) ),
241+ Files .write (bagInfoFilePath , line .getBytes (charsetName ),
240242 StandardOpenOption .APPEND , StandardOpenOption .CREATE );
241243 }
242244 }
@@ -250,15 +252,14 @@ public static void writeBagitInfoFile(List<Pair<String, String>> metadata, Versi
250252 *
251253 * @throws IOException if there was a problem writing a file
252254 */
253- public static void writeFetchFile (List <FetchItem > itemsToFetch , Path outputDir , String charsetName ) throws IOException {
255+ public static void writeFetchFile (List <FetchItem > itemsToFetch , Path outputDir , Charset charsetName ) throws IOException {
254256 logger .debug ("Writing fetch.txt to [{}]" , outputDir );
255257 Path fetchFilePath = outputDir .resolve ("fetch.txt" );
256258
257259 for (FetchItem item : itemsToFetch ){
258260 String line = item .toString ();
259261 logger .debug ("Writing [{}] to [{}]" , line , fetchFilePath );
260- Files .write (fetchFilePath , line .getBytes (Charset .forName (charsetName )),
261- StandardOpenOption .APPEND , StandardOpenOption .CREATE );
262+ Files .write (fetchFilePath , line .getBytes (charsetName ), StandardOpenOption .APPEND , StandardOpenOption .CREATE );
262263 }
263264 }
264265}
0 commit comments