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

issue #76: Ability to read xport files (v5 and v8) #85

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
78 changes: 77 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,14 @@
![Version](https://img.shields.io/maven-central/v/com.epam/parso)

# Parso Java library

## Parso 3.0
***1 February 2021***

* Implemented reading of SAS Transport File Format (XPORT): Version 5 and Version 8 (not tested)

[i54]: https://github.com/epam/parso/issues/76

## Parso 2.0.13
***17 December 2020***

Expand Down Expand Up @@ -159,10 +167,12 @@ If you use Maven, add the following dependency into the pom.xml file:
<dependency>
<groupId>com.epam</groupId>
<artifactId>parso</artifactId>
<version>2.0.13</version>
<version>3.0</version>
</dependency>
```

***Working with SAS7BDAT files***

Create a variable of the SasFileReader class and indicate your InputStream that contains the SAS7BDAT file as a parameter in the SasFileReader constructor:
```java
com.epam.parso.SasFileReader sasFileReader = new SasFileReaderImpl(is);
Expand Down Expand Up @@ -212,6 +222,72 @@ To write rows one by one to the ‘writer’ variable:
csvDataWriter.writeRow(sasFileReader.getColumns(), sasFileReader.readNext());
```

***Working with XPORT files***

Create a variable of the XportFileReader class and specify your XPORT source file (Version 5 or 8)
and Xport version:
```java
com.epam.parso.xport.XportFileReader xportFileReader = new XportFileReaderImpl(file, XportVersion.VERSION_5);
```

To get the properties of a XPORT file, use:
```java
xportFileReader.getXportFileProperties();
```

XPORT file can contain several datasets.

You can process the file iteratively.
When you create xportFileReader instance, the cursor is set to the start of the first dataset (with index 0).

To read current dataset line by line, use:

```java
sasFileReader.readNext(); //to read rows one by one
```

To switch to the next dataset, use:

```java
xportFileReader.nextDataset();
```

To get all data of the XPORT file, use:

```java
xportFileReader.readAll(); //to read all rows in all datasets at once

xportFileReader.readAllInDatasets(); //to read all rows in specified datasets at once

xportFileReader.readAllInCurrentDataset(); //to read all rows in current dataset. You can use it if you know that your file contains only one dataset
```

To convert the metadata of the file into CSV format, use:

```java
Writer writer = new StringWriter();
CSVMetadataWriter csvMetadataWriter = new CSVMetadataWriterImpl(writer);
csvMetadataWriter.writeMetadata(xportFileReader.getColumns());
```
To convert the data of the file into CSV format, use:

```java
Writer writer = new StringWriter();
CSVDataWriter csvDataWriter = new CSVDataWriterImpl(writer);
csvDataWriter.writeColumnNames(xportFileReader.getCurrentDatasetMetadata().getColumns());
```

To write all rows at once to the ‘writer’ variable:

```java
csvDataWriter.writeRowsArray(xportFileReader.getCurrentDatasetMetadata().getColumns(), xportFileReader.readAllInCurrentDataset());
```
To write rows one by one to the ‘writer’ variable:

```java
csvDataWriter.writeRow(xportFileReader.getCurrentDatasetMetadata().getColumns(), xportFileReader.readNext());
```

## License
Copyright (C) 2015 EPAM

Expand Down
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.epam</groupId>
<artifactId>parso</artifactId>
<version>2.0.14-SNAPSHOT</version>
<version>3.0</version>
<packaging>jar</packaging>
<name>parso</name>
<description>Parso is a lightweight Java library designed to read SAS7BDAT datasets. The Parso interfaces
Expand Down Expand Up @@ -214,6 +214,20 @@
<version>1.7.5</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.16</version>
<scope>provided</scope>
</dependency>

<!-- 'bigdoc' allows searching bytes or words in gigabyte order files with high performance -->
<dependency>
<groupId>org.riversun</groupId>
<artifactId>bigdoc</artifactId>
<version>0.3.0</version>
</dependency>

<!-- Test dependencies -->
<dependency>
<groupId>junit</groupId>
Expand Down
9 changes: 9 additions & 0 deletions src/main/java/com/epam/parso/CSVMetadataWriter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package com.epam.parso;

import com.epam.parso.xport.XportFileProperties;
import java.io.IOException;
import java.util.List;

Expand All @@ -41,4 +42,12 @@ public interface CSVMetadataWriter {
* @throws IOException appears if the output into writer is impossible.
*/
void writeSasFileProperties(SasFileProperties sasFileProperties) throws IOException;

/**
* The method to output the xport file properties.
*
* @param xportFileProperties the variable with sas file properties data.
* @throws IOException appears if the output into writer is impossible.
*/
void writeXportFileProperties(XportFileProperties xportFileProperties) throws IOException;
}
2 changes: 1 addition & 1 deletion src/main/java/com/epam/parso/ColumnFormat.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class ColumnFormat {
* The constructor that defines all parameters of the ColumnFormat class.
*
* @param name - column format name.
* @param width - olumn format width.
* @param width - column format width.
* @param precision - column format precision.
*/
public ColumnFormat(String name, int width, int precision) {
Expand Down
Loading