-
Notifications
You must be signed in to change notification settings - Fork 74
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 #87 from alipay/20230324-template
writer buffix
- Loading branch information
Showing
8 changed files
with
74 additions
and
14 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
40 changes: 40 additions & 0 deletions
40
rdf-file-core/src/main/java/com/alipay/rdf/file/common/FileWriterTemplate.java
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,40 @@ | ||
/* | ||
* Ant Group | ||
* Copyright (c) 2004-2023 All Rights Reserved. | ||
*/ | ||
package com.alipay.rdf.file.common; | ||
|
||
import com.alipay.rdf.file.interfaces.FileFactory; | ||
import com.alipay.rdf.file.interfaces.FileWriter; | ||
import com.alipay.rdf.file.model.FileConfig; | ||
import com.alipay.rdf.file.util.RdfFileUtil; | ||
|
||
/** | ||
* @author quhongwei | ||
* @version FileWriterTemplate.java, v 0.1 2023年03月24日 2:07 下午 quhongwei Exp $ | ||
*/ | ||
public abstract class FileWriterTemplate { | ||
private final FileWriter fileWriter; | ||
|
||
public FileWriterTemplate(FileConfig fileConfig) { | ||
this.fileWriter = FileFactory.createWriter(fileConfig); | ||
} | ||
|
||
public void process() throws Throwable { | ||
try { | ||
doProcess(fileWriter); | ||
} catch (Throwable t) { | ||
RdfFileUtil.setWriteError(fileWriter); | ||
|
||
if (t instanceof RuntimeException) { | ||
throw t; | ||
} else { | ||
throw new RuntimeException("rdf-file#FileWriterTemplate file write error.", t); | ||
} | ||
} finally { | ||
fileWriter.close(); | ||
} | ||
} | ||
|
||
protected abstract void doProcess(FileWriter fileWriter) throws Throwable; | ||
} |
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
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
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