Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control of temporary files #78

Merged
merged 1 commit into from
Dec 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions java/developer-guide/control-temporary-files.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
---
id: control-temporary-files
url: viewer/java/control-temporary-files
title: Control temporary files
weight: 7
description: "By following this guide, you will learn how to control temporary files used by GroupDocs.Viewer for Java."
keywords: control temporary files
productName: GroupDocs.Viewer for Java
hideChildren: False
toc: True
structuredData:
showOrganization: True
application:
name: Document Viewer
description: Manage temporary files creation in GroupDocs.Viewer for Java
productCode: viewer
productPlatform: java
showVideo: True
howTo:
name: How to control temporary files creation in GroupDocs.Viewer for Java
description: Learn how to control temporary files creation in GroupDocs.Viewer for Java
steps:
- name: Create a class to control temporary files
text: Create a class that will implement TemporaryFileManager interface with it's methods.
- name: Setup GroupDocs.Viewer for Java to use the class
text: Use method setInstance of TemporaryFileManagerFactory class to make it use custom TemporaryFileManager implementation.
---

[GroupDocs.Viewer](https://products.groupdocs.com/viewer/java) allows you to control a way temporary files and directories is created. Follow these steps to implement custom logic for creating temporary files and folders:

1. Create a class that implements the `com.groupdocs.viewer.common.tempfiles.TemporaryFileManager` interface and its methods:

{{< tabs "example1">}}
{{< tab "Java" >}}
```java
class CustomTemporaryFileManager implements TemporaryFileManager {

@Override
public Path createTempDirectory() {
// Implementation
}

@Override
public Path createTempDirectory(String... pathsAsStrings) {
// Implementation
}

@Override
public Path createTempDirectory(Path... paths) {
// Implementation
}

@Override
public Path createTempFile() {
// Implementation
}

@Override
public Path createTempFile(String... pathsAsStrings) {
// Implementation
}

@Override
public Path createTempFile(Path... paths) {
// Implementation
}

@Override
public void delete(Path path) {
// Implementation
}

@Override
public void cleanup() {
// Implementation
}
}
```
{{< /tab >}}
{{< /tabs >}}

2. Create an object of the class and specify it as a parameter of the `setInstance` method of `TemporaryFileManagerFactory`:
{{< tabs "example2">}}
{{< tab "Java" >}}
```java
final CustomTemporaryFileManager customTemporaryFileManager = new CustomTemporaryFileManager();
TemporaryFileManagerFactory.setInstance(customTemporaryFileManager);
```
{{< /tab >}}
{{< /tabs >}}
Now [GroupDocs.Viewer](https://products.groupdocs.com/viewer/java) uses this implementation for creating temporary files and directories.

3. Use the implementation for your needs as follows:

{{< tabs "example3">}}
{{< tab "Java" >}}
```java
final TemporaryFileManager temporaryFileManager = TemporaryFileManagerFactory.getInstance();
final Path tempFile = temporaryFileManager.createTempFile("temp.txt");
// Do something with the file
temporaryFileManager.delete(tempFile);
```
{{< /tab >}}
{{< /tabs >}}

{{< alert style="info" >}}

Default implementation creates the temporary files and directories in a directory specified by the `java.io.tmpdir` property.

{{< /alert >}}
2 changes: 1 addition & 1 deletion java/developer-guide/troubleshooting/_index.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
id: troubleshooting
url: viewer/java/troubleshooting
title: Troubleshooting
weight: 7
weight: 8
description: "This section contains issues that you may face and solutions for them when processing files with GroupDocs.Viewer."
keywords: "groupdocs viewer java, troubleshooting, known issues"
productName: GroupDocs.Viewer for Java
Expand Down
Loading