1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20 package org.apache.geronimo.javamail.store.nntp.newsrc;
21
22 import java.io.BufferedReader;
23 import java.io.File;
24 import java.io.FileInputStream;
25 import java.io.FileOutputStream;
26 import java.io.IOException;
27 import java.io.InputStreamReader;
28 import java.io.OutputStreamWriter;
29 import java.io.Writer;
30
31 public class NNTPNewsrcFile extends NNTPNewsrc {
32 // source for the file data
33 File source;
34
35 /**
36 * Construct a NNTPNewsrc object that is targetted at a file-based backing
37 * store.
38 *
39 * @param source
40 * The source File for the .newsrc data.
41 */
42 public NNTPNewsrcFile(File source) {
43 this.source = source;
44 }
45
46 /**
47 * Retrieve an input reader for loading the newsrc file.
48 *
49 * @return A BufferedReader object for reading from the newsrc file.
50 * @exception IOException
51 */
52 public BufferedReader getInputReader() throws IOException {
53 return new BufferedReader(new InputStreamReader(new FileInputStream(source)));
54 }
55
56 /**
57 * Obtain a writer for saving a newsrc file.
58 *
59 * @return The output writer targetted to the newsrc file.
60 * @exception IOException
61 */
62 public Writer getOutputWriter() throws IOException {
63 // open this for overwriting
64 return new OutputStreamWriter(new FileOutputStream(source, false));
65 }
66 }