Package com.myscript.iink
Class ContentPackage
java.lang.Object
com.myscript.iink.ContentPackage
- All Implemented Interfaces:
AutoCloseable
A package stores the user content as a sorted collection of parts.
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionfinal @NotNull ContentPart
clonePart
(@NotNull ContentPart part) Adds an existing part to this package.final void
close()
final @NotNull ContentPart
createPart
(@NotNull String type) Appends a new part to this package.final void
extractObject
(@NotNull String url, @NotNull File file) Extracts an object from this package to a given file.protected void
finalize()
final @NotNull ParameterSet
Returns this package's metadata as a parameter set.final @NotNull ContentPart
getPart
(int index) Returns the part at the specified index.final @NotNull ContentPart
Returns the specified part.final int
Returns the number of parts in this package.final @NotNull String
getPath()
Returns the path of this package.final int
indexOfPart
(@NotNull ContentPart part) Returns the index of a given part.final boolean
isClosed()
Tells whether theclose()
method has been called.final void
movePart
(int fromIndex, int toIndex) Moves the specified part to another index.final void
removePart
(@NotNull ContentPart part) Removes the specified part.final void
save()
Saves all ongoing modifications made to this package.final void
Saves all ongoing modifications made to this package, to a new file.final void
Saves all ongoing modifications made to this package to a temporary folder.final void
setMetadata
(@NotNull ParameterSet parameters) Set this package's metadata with the given parameter set.@NotNull String
toString()
Returns a String representation of the object.
-
Method Details
-
finalize
-
close
public final void close()- Specified by:
close
in interfaceAutoCloseable
-
isClosed
public final boolean isClosed()Tells whether theclose()
method has been called. Once an object is closed any method will throwIllegalStateException
.- Returns:
true
if this object is closed.
-
save
Saves all ongoing modifications made to this package.- Throws:
IllegalStateException
- when this package is closed.IOException
- when an I/O operation fails.
-
saveToTemp
Saves all ongoing modifications made to this package to a temporary folder. This operation is faster thansave()
.Note: by default temporary folder is located in the same directory as this package, and named by appending
-files
to this package's name.Note: temporary folder location can be set via the
content-package.temp-folder
configuration property.- Throws:
IllegalStateException
- when this package is closed.IOException
- when an I/O operation fails.
-
saveAs
Saves all ongoing modifications made to this package, to a new file.- Parameters:
file
- the new file name.- Throws:
IllegalStateException
- when this package is closed.IOException
- when an I/O operation fails.
-
getPartCount
public final int getPartCount()Returns the number of parts in this package.- Returns:
- the part count.
- Throws:
IllegalStateException
- when this package is closed.
-
getPart
Returns the part at the specified index.- Parameters:
index
- the index of the requested part.- Returns:
- the requested part.
- Throws:
IllegalStateException
- when this package is closed.IndexOutOfBoundsException
- whenindex
is out of range.
-
getPart
@NotNull public final @NotNull ContentPart getPart(@NotNull @NotNull String id) throws IllegalArgumentException Returns the specified part.- Parameters:
id
- the identifier of the requested part.- Returns:
- the part.
- Throws:
IllegalStateException
- when this package is closed.IllegalArgumentException
- when no part is associated with identifierid
.
-
indexOfPart
Returns the index of a given part.- Parameters:
part
- the part.- Returns:
- the index of the part, or -1 if the part does not belong to this package.
- Throws:
IllegalStateException
- when this package is closed.IllegalStateException
- when this package's part is closed.
-
createPart
@NotNull public final @NotNull ContentPart createPart(@NotNull @NotNull String type) throws IllegalArgumentException Appends a new part to this package.- Parameters:
type
- the type of part.- Returns:
- the newly created part.
- Throws:
IllegalStateException
- when this package is closed.IllegalArgumentException
- whentype
is not a valid ContentPart type.
-
removePart
Removes the specified part.- Parameters:
part
- the part to remove.- Throws:
IllegalStateException
- when this package is closed.IllegalStateException
- when this package's part is closed.IllegalArgumentException
- when part does not belong to this package.- Since:
- 1.2
-
movePart
Moves the specified part to another index.- Parameters:
fromIndex
- the current index of the requested part.toIndex
- the new index of the part.- Throws:
IllegalStateException
- when this package is closed.IllegalArgumentException
- when fromIndex is out of range.IllegalArgumentException
- when toIndex is out of range.IndexOutOfBoundsException
- Since:
- 2.1.1
-
clonePart
Adds an existing part to this package.Note: Part modifications that have not been saved (to temporary directory or to an actual package file) will not be imported.
Note: The part can be an existing part from this package or from another open package.
- Parameters:
part
- the part to clone into this package.- Returns:
- the newly created part.
- Throws:
IllegalStateException
- when this package is closed.IllegalStateException
- when this package's part is closed.IllegalArgumentException
- whenpart
is not valid.- Since:
- 1.2
-
extractObject
public final void extractObject(@NotNull @NotNull String url, @NotNull @NotNull File file) throws IOException, IllegalArgumentException Extracts an object from this package to a given file.- Parameters:
url
- URL of the object.file
- destination file.- Throws:
IllegalStateException
- when this package is closed.IllegalArgumentException
- when no object namedurl
exists.IOException
- when an I/O operation fails.
-
getMetadata
Returns this package's metadata as a parameter set.- Returns:
- the metadata.
- Throws:
IllegalStateException
- when this package is closed.
-
setMetadata
Set this package's metadata with the given parameter set.- Parameters:
parameters
- the metadata.- Throws:
IllegalStateException
- when this package is closed.IllegalStateException
- whenparameters
is closed.
-
getPath
Returns the path of this package.- Returns:
- the path.
- Throws:
IllegalStateException
- when this package is closed.- Since:
- 2.0
-
toString
Returns a String representation of the object.
-