GroupDocs.Redaction を使用した Java のカスタムフォーマットハンドラの実装

In today’s data‑driven environment, protecting sensitive information is a non‑negotiable requirement. Implement custom format handler in Java gives you the flexibility to work with any file type—whether it’s a legal contract, a financial statement, or a simple plain‑text dump—while still leveraging GroupDocs.Redaction’s high‑performance redaction engine. This tutorial walks you through registering a custom format handler for plain‑text files, applying redactions, and finally save redacted document files safely.

クイック回答

学べること

カスタムフォーマットハンドラとは?

A custom format handler is a plug‑in that tells GroupDocs.Redaction how to interpret a non‑standard file type. It maps a file extension to a document class so the redaction engine can read, modify, and write the content just like it does for built‑in formats.

カスタムフォーマットに GroupDocs.Redaction を使用する理由

GroupDocs.Redaction supports 45+ input and output formats and can process files up to 2 GB without loading the entire document into memory. Its streaming architecture reduces CPU usage by up to 30 % compared with naïve file‑loading approaches, making it ideal for high‑volume batch jobs.

前提条件

Before we begin, ensure you have the following:

必要なライブラリとバージョン

環境設定要件

知識の前提条件

Java 用 GroupDocs.Redaction の設定

To integrate GroupDocs.Redaction into your Java application, you have two main methods: using Maven or direct download. We’ll walk through both so you can choose the approach that matches your workflow.

Maven の使用

Add the following configuration to your pom.xml file:

<repositories>
   <repository>
      <id>repository.groupdocs.com</id>
      <name>GroupDocs Repository</name>
      <url>https://releases.groupdocs.com/redaction/java/</url>
   </repository>
</repositories>

<dependencies>
   <dependency>
      <groupId>com.groupdocs</groupId>
      <artifactId>groupdocs-redaction</artifactId>
      <version>24.9</version>
   </dependency>
</dependencies>

直接ダウンロード

Alternatively, download the latest version directly from GroupDocs.Redaction for Java releases.

ライセンス取得手順

  1. Free trial – explore the full feature set without cost.
  2. Temporary license – obtain a time‑limited key for extended testing.
  3. Purchase – acquire a permanent license for production deployments.

基本的な初期化と設定

Once the library is available on the classpath, initialize GroupDocs.Redaction as follows:

import com.groupdocs.redaction.Redactor;
import com.groupdocs.redaction.options.SaveOptions;

public class InitializeRedaction {
    public static void main(String[] args) throws Exception {
        Redactor redactor = new Redactor("path/to/your/document");
        // Perform operations with the redactor instance.
        redactor.close();
    }
}

With GroupDocs.Redaction set up, we can now dive into how to implement custom format handler and apply redactions.

Java でカスタムフォーマットハンドラを実装する方法

機能 1: カスタムフォーマットハンドラの登録

概要

Registering a custom format handler extends GroupDocs.Redaction’s capabilities to handle specific document types, such as plain‑text files with unique extensions.

手順実装

手順 1: 必要なクラスをインポート

Begin by importing the necessary configuration classes:

import com.groupdocs.redaction.configuration.DocumentFormatConfiguration;
import com.groupdocs.redaction.integration.DocumentFormatInstance;
import com.groupdocs.redaction.examples.java.helper_classes.CustomTextualDocument;
手順 2: ドキュメントフォーマットを設定

setExtensionFilter specifies which file extensions the custom handler will process.
setDocumentType links the extension to a concrete document class that knows how to read and write the format.

Set up the document format configuration to specify which file extension and class handle the custom format:

class CustomFormatHandlerRegistration {
    public static void main(String[] args) {
        DocumentFormatConfiguration config = new DocumentFormatConfiguration();
        // Set the file extension for this handler.
        config.setExtensionFilter(".dump");
        // Specify handling by CustomTextualDocument class.
        config.setDocumentType(CustomTextualDocument.class);
        // Add to available formats list.
        DocumentFormatInstance.getDefaultConfiguration().getAvailableFormats().add(config);
    }
}

機能 2: レダクションの適用

概要

This feature demonstrates how to redact text java documents, ensuring that any replace sensitive text operation is performed safely and audit‑ably.

手順実装

手順 1: 必要なクラスをインポート

Import the classes needed for performing redactions:

import com.groupdocs.redaction.Redactor;
import com.groupdocs.redaction.options.SaveOptions;
import com.groupdocs.redaction.redactions.ExactPhraseRedaction;
import com.groupdocs.redaction.redactions.ReplacementOptions;
手順 2: Redactor を初期化しレダクションを適用

Redactor is the core class that loads a document and applies redaction operations.
Create a Redactor instance with the path to your source file, add the desired redaction objects, and save redacted document under a new name:

class RedactionApplication {
    public static void main(String[] args) throws Exception {
        final Redactor redactor = new Redactor(YOUR_DOCUMENT_DIRECTORY + "/sample.dump");
        try {
            // Apply an exact phrase redaction.
            redactor.apply(new ExactPhraseRedaction("dolor", false, new ReplacementOptions("[redacted]")));
            // Save the document with a new name.
            redactor.save(new SaveOptions(false, "AnyText"));
        } finally {
            redactor.close();
        }
    }
}

トラブルシューティングのヒント

実用的な応用例

Here are some real‑world scenarios where these techniques can be applied:

  1. Legal document protection – redact case details before sharing drafts with external counsel.
  2. Financial records security – obscure account numbers and personal identifiers in bank statements.
  3. HR data management – mask employee personal data during audits or third‑party reviews.
  4. CRM integration – automatically redact customer PII before exporting reports from a CRM system.
  5. Automated compliance reporting – ensure regulatory documents contain no accidental data leaks.

パフォーマンスに関する考慮事項

When working with GroupDocs.Redaction, consider these tips for optimal performance:

よくある問題と解決策

IssueCauseSolution
Handler not recognizedExtension filter mismatchVerify setExtensionFilter matches the file’s extension exactly (e.g., .dump).
Redaction not appliedPhrase case‑sensitivitySet the ignoreCase flag to true in ExactPhraseRedaction.
Out‑of‑memory errorsLarge files loaded simultaneouslyProcess files sequentially or use streaming APIs where available.

よくある質問

Q1: カスタムフォーマットハンドラでどのファイルタイプを扱えますか?
A1: 拡張子と対応するドキュメントクラスを指定することで、任意のファイルタイプにハンドラを設定でき、ネイティブにサポートされていないフォーマットでもレダクションが可能になります。

Q2: GroupDocs.Redaction の一時ライセンスはどう取得しますか?
A: Visit GroupDocs’ official site to request a temporary license key for extended testing.

Q3: 大量のドキュメントを効率的にバッチ処理できますか?
A: Yes—use the batch‑processing tips in the Performance Considerations section and close each Redactor instance promptly to keep memory usage low.

Q4: 同じハンドラで PDF ファイルをレダクトできますか?
A: GroupDocs.Redaction already includes native PDF support; custom handlers are typically reserved for non‑standard formats like .dump or proprietary log files.

Q5: API は非同期操作をサポートしていますか?
A: The core API is synchronous, but you can wrap calls in Java CompletableFuture or employ parallel streams to achieve concurrency.

結論

By now you should have a solid grasp of how to implement custom format handler and redact text java documents using GroupDocs.Redaction for Java. These capabilities empower you to protect sensitive information across a wide range of document types, from plain‑text logs to complex legal contracts. To deepen your expertise, explore pattern‑based redaction, integrate the workflow into CI/CD pipelines, and monitor performance with Java profiling tools.

次のステップ


最終更新日: 2026-09-06
テスト環境: GroupDocs.Redaction 24.9
作者: GroupDocs

関連チュートリアル