eu.stratosphere.nephele.io.library.DirectoryWriter Maven / Gradle / Ivy
/***********************************************************************************************************************
* Copyright (C) 2010-2013 by the Stratosphere project (http://stratosphere.eu)
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
**********************************************************************************************************************/
package eu.stratosphere.nephele.io.library;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import eu.stratosphere.core.fs.FSDataOutputStream;
import eu.stratosphere.core.fs.FileSystem;
import eu.stratosphere.core.fs.Path;
import eu.stratosphere.nephele.io.RecordReader;
import eu.stratosphere.nephele.template.AbstractFileOutputTask;
import eu.stratosphere.nephele.types.FileRecord;
public class DirectoryWriter extends AbstractFileOutputTask {
/**
* The record reader to read the incoming strings from.
*/
private RecordReader input = null;
private static final Log LOG = LogFactory.getLog(DirectoryWriter.class);
@Override
public void invoke() throws Exception {
final Path path = getFileOutputPath();
final FileSystem fs = path.getFileSystem();
try {
while (input.hasNext()) {
final FileRecord record = input.next();
Path newPath = new Path(path + Path.SEPARATOR + record.getFileName());
FSDataOutputStream outputStream = fs.create(newPath, true);
outputStream.write(record.getDataBuffer(), 0, record.getDataBuffer().length);
outputStream.close();
// TODO: Implement me
// System.out.println(input.next());
// ODO Auto-generated catch block
}
} catch (InterruptedException e) {
// TODO Auto-generated catch block
LOG.error(e);
}
}
@Override
public void registerInputOutput() {
input = new RecordReader(this, FileRecord.class);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy