// Path: Engine/SCommon/src/com/ibm/storlet/common/IStorlet.java
// public interface IStorlet 
// {
//     public void invoke(ArrayList<StorletInputStream>  inStreams, 
// 	                   ArrayList<StorletOutputStream> outStreams, 
// 	                   Map<String,String>             parameters, 
// 	                   StorletLogger                  logger) 
// 	                                                  throws StorletException;
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletException.java
// public class StorletException extends Exception {
//     /**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	public StorletException(String message) {
//         super(message);
//     }
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletInputStream.java
// public class StorletInputStream {
// 	private HashMap<String, String> metadata;
// 	private InputStream stream;
// 	
// 	public StorletInputStream(FileDescriptor fd, HashMap<String, String> md) {
// 		stream = ((InputStream)(new FileInputStream(fd)));
// 		metadata = md;
// 	}
// 
// 	public HashMap<String, String> getMetadata() {
// 		return metadata;
// 	}
// 
// 	public InputStream getStream() {
// 		return stream;
// 	}	
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletLogger.java
// public class StorletLogger {
// 	private FileOutputStream stream;
// 
// 	public StorletLogger(FileDescriptor fd) {
// 		stream = new FileOutputStream(fd);
// 	}
// 	
// 	public void emitLog(String message) {
// 		message = message + "\n";
// 		try {
// 			stream.write(message.getBytes());
// 		} catch (IOException e){
// 			
// 		}
// 		
// 	}
// 	
// 	public void Flush() {
// 		try {
// 			stream.flush();
// 		} catch (IOException e) {
// 		}		
// 	}
// 	
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletObjectOutputStream.java
// public class StorletObjectOutputStream extends StorletOutputStream 
// {
// 
//     private OutputStream MetadataStream_;	
// 	
// 	public StorletObjectOutputStream( FileDescriptor           data_fd, 
// 			                          HashMap<String, String>  data_md, 
// 			                          FileDescriptor           md_fd ) 
// 	{
// 		super( data_fd, data_md );
// 		MetadataStream_ = ((OutputStream)(new FileOutputStream(md_fd)));
// 	}
// 	
//     public OutputStream getStream() 
//     {
//         return stream;
//     }
// 
//     public OutputStream getMDStream() 
//     {
//         return MetadataStream_;
//     }
// 
// 	@SuppressWarnings("unchecked")
//     public void setMetadata( Map<String, String> md ) 
//                                                      throws StorletException 
//     {
// 		JSONObject jobj = new JSONObject();
// 		Iterator<Map.Entry<String,String>> it = md.entrySet().iterator();
// 	    while( it.hasNext() ) 
// 	    {
// 	        Map.Entry<String,String> pairs = 
// 	                                 (Map.Entry<String,String>) it.next();
// 	        jobj.put( (String) pairs.getKey(), (String) pairs.getValue() );
// 	        it.remove();
// 	    }
// 	    try 
// 	    {
// 	        MetadataStream_.write( jobj.toString().getBytes() );
// 	        MetadataStream_.close();
// 	    } 
// 	    catch( IOException e )
// 	    {
// 	    	throw 
// 	    	    new StorletException("Failed to set metadata "+ e.toString());
// 	    }
// 	}	
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletOutputStream.java
// public class StorletOutputStream {
// 	private HashMap<String, String> metadata;
// 	protected OutputStream stream;
// 	
// 	public StorletOutputStream(FileDescriptor fd, HashMap<String, String> md) {
// 		stream = ((OutputStream)(new FileOutputStream(fd)));
// 		metadata = md;
// 	}
// 
// 	public HashMap<String, String> getMetadata() {
// 		return metadata;
// 	}
// }


import com.ibm.storlet.common.StorletInputStream;
import com.ibm.storlet.common.StorletLogger;
import com.ibm.storlet.common.StorletObjectOutputStream;
import com.ibm.storlet.common.StorletOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.io.InputStream;
import java.io.OutputStream;
import com.ibm.storlet.common.IStorlet;
import com.ibm.storlet.common.StorletException;
/*----------------------------------------------------------------------------
 * Copyright IBM Corp. 2015, 2015 All Rights Reserved
 * 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.
 * ---------------------------------------------------------------------------
 */

/*============================================================================
 07-Jul-2015    cdoron     Initial implementation.
 ===========================================================================*/

package com.ibm.storlet.half;



public class HalfStorlet implements IStorlet 
{
    @Override
    public void invoke( ArrayList<StorletInputStream>  inputStreams,
                        ArrayList<StorletOutputStream> outputStreams, 
                        Map<String, String>            parameters,
                        StorletLogger                  log ) 
                                                       throws StorletException {
    	log.emitLog("HalfStorlet Invoked");
    	
	StorletInputStream sis = inputStreams.get(0);
		
	StorletObjectOutputStream storletObjectOutputStream;
// Path: Engine/SCommon/src/com/ibm/storlet/common/IStorlet.java
// public interface IStorlet 
// {
//     public void invoke(ArrayList<StorletInputStream>  inStreams, 
// 	                   ArrayList<StorletOutputStream> outStreams, 
// 	                   Map<String,String>             parameters, 
// 	                   StorletLogger                  logger) 
// 	                                                  throws StorletException;
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletException.java
// public class StorletException extends Exception {
//     /**
// 	 * 
// 	 */
// 	private static final long serialVersionUID = 1L;
// 
// 	public StorletException(String message) {
//         super(message);
//     }
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletInputStream.java
// public class StorletInputStream {
// 	private HashMap<String, String> metadata;
// 	private InputStream stream;
// 	
// 	public StorletInputStream(FileDescriptor fd, HashMap<String, String> md) {
// 		stream = ((InputStream)(new FileInputStream(fd)));
// 		metadata = md;
// 	}
// 
// 	public HashMap<String, String> getMetadata() {
// 		return metadata;
// 	}
// 
// 	public InputStream getStream() {
// 		return stream;
// 	}	
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletLogger.java
// public class StorletLogger {
// 	private FileOutputStream stream;
// 
// 	public StorletLogger(FileDescriptor fd) {
// 		stream = new FileOutputStream(fd);
// 	}
// 	
// 	public void emitLog(String message) {
// 		message = message + "\n";
// 		try {
// 			stream.write(message.getBytes());
// 		} catch (IOException e){
// 			
// 		}
// 		
// 	}
// 	
// 	public void Flush() {
// 		try {
// 			stream.flush();
// 		} catch (IOException e) {
// 		}		
// 	}
// 	
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletObjectOutputStream.java
// public class StorletObjectOutputStream extends StorletOutputStream 
// {
// 
//     private OutputStream MetadataStream_;	
// 	
// 	public StorletObjectOutputStream( FileDescriptor           data_fd, 
// 			                          HashMap<String, String>  data_md, 
// 			                          FileDescriptor           md_fd ) 
// 	{
// 		super( data_fd, data_md );
// 		MetadataStream_ = ((OutputStream)(new FileOutputStream(md_fd)));
// 	}
// 	
//     public OutputStream getStream() 
//     {
//         return stream;
//     }
// 
//     public OutputStream getMDStream() 
//     {
//         return MetadataStream_;
//     }
// 
// 	@SuppressWarnings("unchecked")
//     public void setMetadata( Map<String, String> md ) 
//                                                      throws StorletException 
//     {
// 		JSONObject jobj = new JSONObject();
// 		Iterator<Map.Entry<String,String>> it = md.entrySet().iterator();
// 	    while( it.hasNext() ) 
// 	    {
// 	        Map.Entry<String,String> pairs = 
// 	                                 (Map.Entry<String,String>) it.next();
// 	        jobj.put( (String) pairs.getKey(), (String) pairs.getValue() );
// 	        it.remove();
// 	    }
// 	    try 
// 	    {
// 	        MetadataStream_.write( jobj.toString().getBytes() );
// 	        MetadataStream_.close();
// 	    } 
// 	    catch( IOException e )
// 	    {
// 	    	throw 
// 	    	    new StorletException("Failed to set metadata "+ e.toString());
// 	    }
// 	}	
// }
// 
// Path: Engine/SCommon/src/com/ibm/storlet/common/StorletOutputStream.java
// public class StorletOutputStream {
// 	private HashMap<String, String> metadata;
// 	protected OutputStream stream;
// 	
// 	public StorletOutputStream(FileDescriptor fd, HashMap<String, String> md) {
// 		stream = ((OutputStream)(new FileOutputStream(fd)));
// 		metadata = md;
// 	}
// 
// 	public HashMap<String, String> getMetadata() {
// 		return metadata;
// 	}
// }


// Path: StorletSamples/HalfStorlet/src/com/ibm/storlet/half/HalfStorlet.java
import com.ibm.storlet.common.StorletInputStream;
import com.ibm.storlet.common.StorletLogger;
import com.ibm.storlet.common.StorletObjectOutputStream;
import com.ibm.storlet.common.StorletOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.io.InputStream;
import java.io.OutputStream;
import com.ibm.storlet.common.IStorlet;
import com.ibm.storlet.common.StorletException;

/*----------------------------------------------------------------------------
 * Copyright IBM Corp. 2015, 2015 All Rights Reserved
 * 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.
 * ---------------------------------------------------------------------------
 */

/*============================================================================
 07-Jul-2015    cdoron     Initial implementation.
 ===========================================================================*/

package com.ibm.storlet.half;



public class HalfStorlet implements IStorlet 
{
    @Override
    public void invoke( ArrayList<StorletInputStream>  inputStreams,
                        ArrayList<StorletOutputStream> outputStreams, 
                        Map<String, String>            parameters,
                        StorletLogger                  log ) 
                                                       throws StorletException {
    	log.emitLog("HalfStorlet Invoked");
    	
	StorletInputStream sis = inputStreams.get(0);
		
	StorletObjectOutputStream storletObjectOutputStream;
	storletObjectOutputStream = (StorletObjectOutputStream)outputStreams.get(0);