001 /* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, 013 * software distributed under the License is distributed on an 014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 015 * KIND, either express or implied. See the License for the 016 * specific language governing permissions and limitations 017 * under the License. 018 */ 019 020 package org.apache.geronimo.javamail.store.nntp.newsrc; 021 022 import java.io.BufferedReader; 023 import java.io.File; 024 import java.io.FileInputStream; 025 import java.io.FileOutputStream; 026 import java.io.IOException; 027 import java.io.InputStreamReader; 028 import java.io.OutputStreamWriter; 029 import java.io.Writer; 030 031 public class NNTPNewsrcFile extends NNTPNewsrc { 032 // source for the file data 033 File source; 034 035 /** 036 * Construct a NNTPNewsrc object that is targetted at a file-based backing 037 * store. 038 * 039 * @param source 040 * The source File for the .newsrc data. 041 */ 042 public NNTPNewsrcFile(File source) { 043 this.source = source; 044 } 045 046 /** 047 * Retrieve an input reader for loading the newsrc file. 048 * 049 * @return A BufferedReader object for reading from the newsrc file. 050 * @exception IOException 051 */ 052 public BufferedReader getInputReader() throws IOException { 053 return new BufferedReader(new InputStreamReader(new FileInputStream(source))); 054 } 055 056 /** 057 * Obtain a writer for saving a newsrc file. 058 * 059 * @return The output writer targetted to the newsrc file. 060 * @exception IOException 061 */ 062 public Writer getOutputWriter() throws IOException { 063 // open this for overwriting 064 return new OutputStreamWriter(new FileOutputStream(source, false)); 065 } 066 }