Text File Utilities

Overview

Append, read, or read lines with filters from a text file.

Key Features & Functionality

Smart Services:

  • appendTextToFile - Append text to a text Document

Functions

  • readTextFromFile - Reads data from a text Document (any extension encoded as text) into a string, with an option to preserve line breaks
  • readMatchingLinesInFile - Reads and returns lines from a text Document which contain a provided search string
  • readMatchingLinesInFileRegex - Reads and returns lines from a text Document which match a provided Regex pattern.
Anonymous
Parents
  • Hi,

    For Append text to file smart service, would it be better to append the content without loading the entire content into a variable? The following seem to be better approach to avoid loading the data into memory. 

    BufferedReader reader = new BufferedReader(new InputStreamReader(documentInputStream));
    Approval a = cs.createVersion(doc, ContentConstants.UNIQUE_NONE);
    Long newVersionId = a.getId()[0];
    Document newDoc = cs.download(newVersionId, ContentConstants.VERSION_CURRENT, false)[0];

    try (DocumentOutputStream documentOutputStream = newDoc.getOutputStream();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(documentOutputStream))) {

    String line;
    while ((line = reader.readLine()) != null) {
    writer.write(line);
    writer.newLine();
    }
    writer.write(textToAppend); // append directly, no memory buildup
    }

Comment
  • Hi,

    For Append text to file smart service, would it be better to append the content without loading the entire content into a variable? The following seem to be better approach to avoid loading the data into memory. 

    BufferedReader reader = new BufferedReader(new InputStreamReader(documentInputStream));
    Approval a = cs.createVersion(doc, ContentConstants.UNIQUE_NONE);
    Long newVersionId = a.getId()[0];
    Document newDoc = cs.download(newVersionId, ContentConstants.VERSION_CURRENT, false)[0];

    try (DocumentOutputStream documentOutputStream = newDoc.getOutputStream();
    BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(documentOutputStream))) {

    String line;
    while ((line = reader.readLine()) != null) {
    writer.write(line);
    writer.newLine();
    }
    writer.write(textToAppend); // append directly, no memory buildup
    }

Children
No Data