/* * #%L * Processiva Business Processes Platform * %% * Copyright (C) 2012 Cohesiva * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. * #L% */ package com.cohesiva.processes.jbpm.serviceImpl.base; import java.io.DataInputStream; import java.io.DataOutputStream; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import org.springframework.stereotype.Service; import com.cohesiva.processes.jbpm.service.base.ISessionManager; @Service public class SessionManager implements ISessionManager { private final String filePath = "session"; private File file; public SessionManager() { try { file = new File(filePath); if (!file.exists()) { file.createNewFile(); } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public int getLatestSessionId() { int sessionId = -1; try { FileInputStream fis = new FileInputStream(file); DataInputStream dis = new DataInputStream(fis); sessionId = dis.readInt(); dis.close(); } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return sessionId; } public void saveLatestSessionId(int sessionId) { try { FileOutputStream fos = new FileOutputStream(file, false); DataOutputStream dos = new DataOutputStream(fos); dos.writeInt(sessionId); dos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }