Search in sources :

Example 1 with FileNodeDataContainer

use of org.structr.cloud.message.FileNodeDataContainer in project structr by structr.

the class CloudConnection method fileChunk.

public void fileChunk(final FileNodeChunk chunk) {
    final FileNodeDataContainer container = fileMap.get(chunk.getContainerId());
    if (container == null) {
        logger.warn("Received file chunk for ID {} without file, this should not happen!", chunk.getContainerId());
    } else {
        container.addChunk(chunk);
        count++;
        total++;
    }
}
Also used : FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer)

Example 2 with FileNodeDataContainer

use of org.structr.cloud.message.FileNodeDataContainer in project structr by structr.

the class PushTransmission method sendFile.

/**
 * Splits the given file and sends it over the client connection. This method first creates a <code>FileNodeDataContainer</code> and sends it to the remote end. The file from disk is then
 * split into multiple instances of <code>FileChunkContainer</code> while being sent. To finalize the transfer, a <code>FileNodeEndChunk</code> is sent to notify the receiving end of the
 * successful transfer.
 *
 * @param client the client to send over
 * @param file the file to split and send
 * @param chunkSize the chunk size for a single chunk
 * @throws org.structr.common.error.FrameworkException
 * @throws java.io.IOException
 */
public static void sendFile(final CloudConnection client, final File file, final int chunkSize) throws FrameworkException, IOException {
    // send file container first
    FileNodeDataContainer container = new FileNodeDataContainer(file);
    client.send(container);
    // send chunks
    for (FileNodeChunk chunk : FileNodeDataContainer.getChunks(file, chunkSize)) {
        client.send(chunk);
    }
    // mark end of file with special chunk
    client.send(new FileNodeEndChunk(container.getSourceNodeId(), container.getFileSize()));
}
Also used : FileNodeEndChunk(org.structr.cloud.message.FileNodeEndChunk) FileNodeChunk(org.structr.cloud.message.FileNodeChunk) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer)

Example 3 with FileNodeDataContainer

use of org.structr.cloud.message.FileNodeDataContainer in project structr by structr.

the class SyncTransmission method sendFile.

/**
 * Splits the given file and sends it over the client connection. This method first creates a <code>FileNodeDataContainer</code> and sends it to the remote end. The file from disk is then
 * split into multiple instances of <code>FileChunkContainer</code> while being sent. To finalize the transfer, a <code>FileNodeEndChunk</code> is sent to notify the receiving end of the
 * successful transfer.
 *
 * @param client the client to send over
 * @param file the file to split and send
 * @param chunkSize the chunk size for a single chunk
 * @throws org.structr.common.error.FrameworkException
 * @throws java.io.IOException
 */
public static void sendFile(final CloudConnection client, final File file, final int chunkSize) throws FrameworkException, IOException {
    // send file container first
    FileNodeDataContainer container = new FileNodeDataContainer(file);
    client.send(container);
    // send chunks
    for (FileNodeChunk chunk : FileNodeDataContainer.getChunks(file, chunkSize)) {
        client.send(chunk);
    }
    // mark end of file with special chunk
    client.send(new FileNodeEndChunk(container.getSourceNodeId(), container.getFileSize()));
}
Also used : FileNodeEndChunk(org.structr.cloud.message.FileNodeEndChunk) FileNodeChunk(org.structr.cloud.message.FileNodeChunk) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer)

Example 4 with FileNodeDataContainer

use of org.structr.cloud.message.FileNodeDataContainer in project structr by structr.

the class CloudConnection method finishFile.

public void finishFile(final FileNodeEndChunk endChunk) throws FrameworkException {
    final FileNodeDataContainer container = fileMap.get(endChunk.getContainerId());
    if (container == null) {
        logger.warn("Received file end chunk for ID {} without file, this should not happen!", endChunk.getContainerId());
    } else {
        container.flushAndCloseTemporaryFile();
        final NodeInterface newNode = storeNode(container);
        if (newNode instanceof FileBase) {
            try {
                container.persistTemporaryFile(((FileBase) newNode).getFileOnDisk().getAbsolutePath());
            } catch (Throwable t) {
                // do not catch specific exception only, we need to be able to shut
                // down the connection gracefully, so we must make sure not to be
                // interrupted here
                logger.warn("Unable to persist file {}: {}", newNode, t.getMessage());
            }
        }
        count++;
        total++;
    }
}
Also used : FileBase(org.structr.web.entity.FileBase) FileNodeDataContainer(org.structr.cloud.message.FileNodeDataContainer) NodeInterface(org.structr.core.graph.NodeInterface)

Aggregations

FileNodeDataContainer (org.structr.cloud.message.FileNodeDataContainer)4 FileNodeChunk (org.structr.cloud.message.FileNodeChunk)2 FileNodeEndChunk (org.structr.cloud.message.FileNodeEndChunk)2 NodeInterface (org.structr.core.graph.NodeInterface)1 FileBase (org.structr.web.entity.FileBase)1