Java tutorial
/******************************************************************************* * Copyright (c) 2014,2015 Hideki Yatomi * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ package net.yatomiya.nicherry.services.bbs; import java.io.*; import java.util.*; import com.squareup.okhttp.*; import net.yatomiya.e4.util.*; import net.yatomiya.nicherry.*; import net.yatomiya.nicherry.model.bbs.*; import net.yatomiya.nicherry.services.bbs.model.*; public class BoardProcessor extends ModelProcessor<BoardId, MBoard> { Map<String, String> settingTxtMap; String headTxt; HttpUrl httpUrl; @Override public BoardManager getManager() { return (BoardManager) super.getManager(); } @Override protected BoardUpdateHandler createUpdateHandler() { return new BoardUpdateHandler(); } @Override public void load() { super.load(); BBSUtils.ensureConsistency(getModel()); loadSettingTxt(); loadHeadTxt(); resetAnalyzedStates(); } protected File getSettingTxtFile() { return new File(getManager().getStorageDirectory(getId()), "setting.txt"); } void loadSettingTxt() { try { byte[] buf = IOUtils.read(getSettingTxtFile()); settingTxtMap = new SettingTxtParser().parse(buf); } catch (IOException e) { // just skip as empty. } } public Map<String, String> getSettingTxtMap() { return Collections.unmodifiableMap(settingTxtMap != null ? settingTxtMap : new HashMap<>()); } protected File getHeadTxtFile() { return new File(getManager().getStorageDirectory(getId()), "head.txt"); } void loadHeadTxt() { try { headTxt = IOUtils.readString(getHeadTxtFile(), NConstants.CHARSET_SHIFT_JIS); } catch (IOException e) { // just skip as empty. } } public String getHeadTxt() { return headTxt; } @Override public void resetAnalyzedStates() { httpUrl = HttpUrl.parse(getModel().getUrl()); } }