class LwM2MImporter {

	public byte[] convert(InputStream fileInput) {
		ByteArrayOutputStream baos = new ByteArrayOutputStream();
		ZipOutputStream zip = new ZipOutputStream(baos);

		try {
			LWM2M lwm2m = parse(fileInput);

			try {
				for (LWM2M.Object obj : lwm2m.getObject()) {

					final ModelId modelId = createModelId(obj);

					ZipEntry fbEntry = new ZipEntry(modelId.getName() + ".fbmodel");
					zip.putNextEntry(fbEntry);
					zip.write(FB_TEMPLATE.create(obj, modelId).getBytes());
					zip.closeEntry();

					ZipEntry mappingEntry = new ZipEntry(modelId.getName() + ".mapping");
					zip.putNextEntry(mappingEntry);
					zip.write(MAPPING_TEMPLATE.create(obj, modelId).getBytes());
					zip.closeEntry();
				}
			} catch (Exception ex) {
				ex.printStackTrace();
			} finally {
				if (zip != null) {
					zip.close();
				}
			}

			return baos.toByteArray();
		} catch (Exception e) {
			throw new RuntimeException(e);
		} finally {
			if (baos != null) {
				try {
					baos.close();
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
	}

}